Вот код:
= 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
Какой атрибут имени в text_area
должен быть form[questions_attributes][0][answer_attribute][content]
, но он показывает. form[questions_attributes][0][answers][content]
.
Вот мои модели.
# 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
Итак, что я получаю в журнале: WARNING: Can't mass-assign protected attributes: answers
Любая помощь будет принята с благодарностью. Спасибо!
обновление
вот журнал, чтобы вы могли видеть, что передается:
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
Обновление 2
Когда я добавляю answers
к attr_accessible
в question.rb
, я получаю ActiveRecord::UnknownAttributeError (unknown attribute: answers)