Class: Cathode::CreateRequest
- Defined in:
- lib/cathode/create_request.rb
Overview
Defines the default behavior for a create 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 create a new 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 create a new resource. If the resource is singular, sets the parent resource ‘id` as well.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cathode/create_request.rb', line 6 def default_action_block proc do begin create_params = instance_eval(&@strong_params) if resource.singular create_params["#{parent_resource_name}_id"] = parent_resource_id end body model.create(create_params) rescue ActionController::ParameterMissing => error body error. status :bad_request end end end |