I am using this in my controller:
def step_params
params.require(@type.underscore.to_sym).permit(
:id, :name, :note, :position, :institution_id, :protocol_id, :sequence_id,:orientation_id,
step_item_attributes: [:id, :note, :name, :position, :institution_id, :sequence_id, :orientation_id, :_destroy ],
step_list_attributes: [:id, :note, :name, :position, :institution_id, :sequence_id, :orientation_id, :_destroy ])
end
And see this in the server log after a form with nested attributes is submitted:
Processing by StepsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"Xm6oMMJ2PLXhHfKS1RkIzG5LrCUAY6vLOF+e9XHgBE4=", "step_list"=>{"name"=>"bob bob", "note"=>"", "step_items_attributes"=>{"1411264481612"=>{"name"=>"", "orientation_id"=>"1", "sequence_id"=>"1", "note"=>"a note", "_destroy"=>"false"}}}, "commit"=>"Create Step list", "type"=>"StepList"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Unpermitted parameters: step_items_attributes
(0.1ms) begin transaction
SQL (0.7ms) INSERT INTO "steps" ("created_at", "institution_id", "name", "note", "updated_at") VALUES (?, ?, ?, ?, ?) [["created_at", "2014-09-21 01:54:49.736556"], ["institution_id", 18], ["name", "bob bob"], ["note", ""], ["updated_at", "2014-09-21 01:54:49.736556"]]
(37.5ms) commit transaction
Redirected to http://localhost:3000/steps/54
Completed 302 Found in 47ms (ActiveRecord: 38.7ms)
Looks to me like "Unpermitted parameters: step_items_attributes"
... is the problem.
Why does my permit method not allow the step_items_attributes hash? How could I figure out what other notation might work?
Your permitted Items sets step_item_attributes
but you trying to pass step_items_attributes
(items) with an 's'. so that's why you get Unpermitted parameters: step_items_attributes