Project and tasks have a one-to-many relationship, and project accepts_nested_attributes_for :tasks.
In the form, my task objects look like:
project[tasks][2][assigned_time]
project[tasks][2][due_time]
When the form is submitted I get a hash like:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"...=", "project"=>{"id"=>"1", "tasks"=>{"1"=>{"assigned_time"=>"09:00", "due_time"=>"17:00"}, "2"=>{"assigned_time"=>"09:00", "due_time"=>"17:00"}}
Then I expect them to be saved by just saving the project object:
project = Project.find(params[:id])
respond_to do |format|
if project.update_attributes(params[:tasks])
But I get:
WARNING: Can't mass-assign protected attributes: id SQL (0.3ms) ROLLBACK Completed in 169ms
ActiveRecord::AssociationTypeMismatch (Task(#2188181260) expected, got Array(#2151973780)):
Any ideas how to fix this?