-
Notifications
You must be signed in to change notification settings - Fork 162
Mass assignment with nested attributes not working #214
Description
I have no idea if I am doing something wrong or if I am hitting a strange use case that strong_parameters is not even supposed to handle or if it is a strong_parameters issue to begin with.
It does seem like strong_parameters is doing something, because i get a few messages, as expected.
Unpermitted parameters: created_at, updated_at
Unpermitted parameters: created_at, updated_at
But absolutely nothing is happening when I do
contact = Contact.first
contact.update(safe_params)
I enabled mysql query logging to see whats going on, and I don't even see the UPDATE or INSERT query being executed.
I have a detailed description of the issue on StackOverflow, but will copy all information into this issue, if needed and if it has something to do with strong_parameters.
http://stackoverflow.com/questions/28059189/unable-to-update-or-create-records-using-post-with-strong-parameters-and-nested
Thank you.
EDIT: After further investigation it does seem strong_parameters and nested attributes related. If i remove nested attributes from my params everything works. Once i put them back in, it silently fails, so I suspect the problem lies somewhere in the way I permit them?
:host_notification_commands_attributes and :service_notification_commands_attributes get posted as an array of objects.
[
{
"id"=>1,
"command_name"=>"command1",
"command_line"=>"/usr/local/bin/command1",
"command_description"=>"Command One",
"created_at"=>"2015-01-19T17:24:12.000Z",
"updated_at"=>"2015-01-21T03:29:03.000Z"
},
{
"id"=>2,
"command_name"=>"command2",
"command_line"=>"/usr/local/bin/command2",
"command_description"=>"Command Two",
"created_at"=>"2015-01-19T17:24:23.000Z",
"updated_at"=>"2015-01-19T17:24:23.000Z"
}
]
Am i permitting them correctly?
params.require(:contact)
.permit(:contact_name,
:host_notification_commands_attributes => [ :id, :command_name, :command_line, :command_description ],
:service_notification_commands_attributes => [:id, :command_name, :command_line, :command_description])