Here's the code:
= form_for @form do |f|
= f.fields_for :questions do |q|
%p
= q.object.content
= q.fields_for :answers do |a|
%p= a.text_area :content
What the name attribute on the text_area should be form[questions_attributes][0][answer_attribute][content] but it's showing. form[questions_attributes][0][answers][content].
Here's my models.
# answer.rb
belongs_to :question
# question.rb
has_one :answer
accepts_nested_attributes_for :answer
# form.rb
has_many :questions, :order => 'position ASC'
accepts_nested_attributes_for :questions
So what I'm getting in the log is WARNING: Can't mass-assign protected attributes: answers
Any help would be greatly appreciated. Thanks!
update
here's the log so you can see what's being passed:
Started POST "/forms/16" for 127.0.0.1 at Fri Mar 09 16:53:58 -0500 2012
Processing by FormsController#update as HTML
Parameters: {"commit"=>"Update Form", "utf8"=>"✓", "id"=>"16", "authenticity_token"=>"mcRJP8XgvE0Cl1JsPryER47+Hbx5DwpEveR1m0R7S6k=", "form"=>{"opportunity_id"=>"1", "questions_attributes"=>{"0"=>{"id"=>"101", "answers"=>{"content"=>"asdfasdf"}}, "1"=>{"id"=>"102", "answers"=>{"content"=>"asdfasdf"}}, "2"=>{"id"=>"103", "answers"=>{"content"=>"asdfasdf"}}, "3"=>{"id"=>"104", "answers"=>{"content"=>""}}, "4"=>{"id"=>"105", "answers"=>{"content"=>""}}, "5"=>{"id"=>"106", "answers"=>{"content"=>""}}, "6"=>{"id"=>"107", "answers"=>{"content"=>""}}, "7"=>{"id"=>"108", "answers"=>{"content"=>""}}}, "status"=>"Not Reviewed", "current_step"=>"", "account_id"=>"1"}}
SQL (0.8ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
Form Load (0.2ms) SELECT "forms".* FROM "forms" WHERE "forms"."id" = 16 LIMIT 1
Question Load (1.1ms) SELECT "questions".* FROM "questions" WHERE "questions"."id" IN (101, 102, 103, 104, 105, 106, 107, 108) AND ("questions".form_id = 16) ORDER BY position ASC
WARNING: Can't mass-assign protected attributes: answers
WARNING: Can't mass-assign protected attributes: answers
WARNING: Can't mass-assign protected attributes: answers
WARNING: Can't mass-assign protected attributes: answers
WARNING: Can't mass-assign protected attributes: answers
WARNING: Can't mass-assign protected attributes: answers
WARNING: Can't mass-assign protected attributes: answers
WARNING: Can't mass-assign protected attributes: answers
Redirected to http://vol.dev/forms/16
Completed 302 Found in 208ms
Update 2
When I add answers to attr_accessible in question.rb I get ActiveRecord::UnknownAttributeError (unknown attribute: answers)