Module: Trax::Controller::PermitParamsFor
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/trax/controller/permit_params_for.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #build_resource ⇒ Object
- #build_resource_params ⇒ Object
- #params_permitter_for_action ⇒ Object
- #update_resource(object, attributes) ⇒ Object
Instance Method Details
#build_resource ⇒ Object
29 30 31 |
# File 'lib/trax/controller/permit_params_for.rb', line 29 def build_resource get_resource_ivar || set_resource_ivar(end_of_association_chain.send(method_for_build, resource_params)) end |
#build_resource_params ⇒ Object
24 25 26 27 |
# File 'lib/trax/controller/permit_params_for.rb', line 24 def build_resource_params _params = request.parameters[resource_request_name] self.class.trax_params_permitters[action_name.to_sym].new(_params).to_serializable_hash end |
#params_permitter_for_action ⇒ Object
17 18 19 20 21 22 |
# File 'lib/trax/controller/permit_params_for.rb', line 17 def params_permitter_for_action action = params[:action] return self.trax_params_permitters[action.to_sym] if self.trax_params_permitters.key?(action.to_sym) return self.trax_params_permitters[:save] if self.trax_params_permitters.key?(:save) && (action == 'create' || action == 'update' || action == 'first_or_create') raise StandardError.new("No param permitter defined for action #{action}") end |
#update_resource(object, attributes) ⇒ Object
33 34 35 |
# File 'lib/trax/controller/permit_params_for.rb', line 33 def update_resource(object, attributes) object.update(attributes) end |