Module: ControllerResources::Extension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/controller_resources/extension.rb
Overview
The DSL mixin for ActionController that allows you to quickly define both singular and collection model resources that can be operated on within the controller. Attempts to DRY up most of the boilerplate code at the top of each controller used to set up its state.
Instance Method Summary collapse
-
#collection ⇒ Object
Reader method for the defined collection resource.
-
#edit_params ⇒ ActionController::Parameters
White-listed parameters for mass assignment as defined by
StrongParameters. -
#model ⇒ Object
Reader method for the defined singular resource.
Instance Method Details
#collection ⇒ Object
Reader method for the defined collection resource.
has been defined.
119 120 121 122 |
# File 'lib/controller_resources/extension.rb', line 119 def collection return unless resource? public_send collection_name end |
#edit_params ⇒ ActionController::Parameters
White-listed parameters for mass assignment as defined by StrongParameters. Throws a ControllerResources::NotDefinedError if no resource block has been defined on this controller.
been defined on this controller.
131 132 133 134 135 |
# File 'lib/controller_resources/extension.rb', line 131 def edit_params fail NotDefinedError unless resource? return params.require(model_name).permit! unless params_to_permit.present? params.require(model_name).permit(*params_to_permit) end |
#model ⇒ Object
Reader method for the defined singular resource.
defined.
110 111 112 113 |
# File 'lib/controller_resources/extension.rb', line 110 def model return unless resource? public_send model_name end |