Class: ModelInfo::AssociationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- ModelInfo::AssociationsController
- Defined in:
- app/controllers/model_info/associations_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/model_info/associations_controller.rb', line 23 def create @associated_model_data = @model_data.send(@associated_model_name).build(permit_params) if @associated_model_data.save redirect_to association_show_path(associated_model_object_id: @associated_model_data.id) else flash[:error] = @associated_model_data.errors. redirect_back(fallback_location: request.referrer) end end |
#destroy ⇒ Object
48 49 50 51 |
# File 'app/controllers/model_info/associations_controller.rb', line 48 def destroy @associated_model_class.find(params[:associated_model_object_id]).destroy redirect_back(fallback_location: request.referrer) end |
#edit ⇒ Object
36 37 |
# File 'app/controllers/model_info/associations_controller.rb', line 36 def edit end |
#index ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/model_info/associations_controller.rb', line 13 def index @macro, @page = params[:macro], params[:page] @associated_model_data = @model_data.send(@associated_model_name) if @macro == 'has_one' || @macro == 'belongs_to' @associated_model_pagination = 1 else @associated_model_pagination = @associated_model_data.page(params[:page]).per(10) end end |
#new ⇒ Object
9 10 11 |
# File 'app/controllers/model_info/associations_controller.rb', line 9 def new @associated_model_data = @model_data.send(@associated_model_name).build end |
#show ⇒ Object
33 34 |
# File 'app/controllers/model_info/associations_controller.rb', line 33 def show end |
#update ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'app/controllers/model_info/associations_controller.rb', line 39 def update if @associated_model_data.update(permit_params) redirect_to association_show_path(associated_model_object_id: params[:associated_model_object_id]) else flash[:error] = @associated_model_data.errors. redirect_back(fallback_location: request.referrer) end end |