Class: Cathode::UpdateRequest
- Defined in:
- lib/cathode/update_request.rb
Overview
Defines the default behavior for an update request.
Instance Attribute Summary
Attributes inherited from Request
#_body, #_status, #action, #context, #custom_logic, #resource
Instance Method Summary collapse
-
#default_action_block ⇒ Object
Sets the default action to update a resource.
Methods inherited from Request
Constructor Details
This class inherits a constructor from Cathode::Request
Instance Method Details
#default_action_block ⇒ Object
Sets the default action to update a resource. If the resource is singular, updates the parent’s associated resource. Otherwise, updates the resource directly.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cathode/update_request.rb', line 7 def default_action_block proc do begin record = if resource.singular parent_model = resource.parent.model.find(parent_resource_id) parent_model.send resource.name else record = model.find(params[:id]) end record.update(instance_eval(&@strong_params)) body record.reload rescue ActionController::ParameterMissing => error body error. status :bad_request end end end |