ここに私のユーザーモデルがあります:
class User < ActiveRecord::Base
has_one :teacher, :dependent => :destroy
accepts_nested_attributes_for :teacher, :allow_destroy => true
attr_accessible :email, :password, :password_confirmation, :remember_me, :teacher_attributes
end
これが私の教師モデルです:
class Teacher < ActiveRecord::Base
belongs_to :user
attr_accessible :user_id, :first_name, :last_name
validates_presence_of :user_id, :first_name, :last_name
end
これが私のフォームです:
<%= form_for(@user, :url => registration_path(:user)) do |user| %>
<%= user.text_field :email %>
<%= user.text_field :password %>
<%= user.text_field :password_confirmation %>
<%= user.fields_for resource.build_teacher do |t| %>
<%= t.text_field :first_name %>
<%= t.text_field :last_name %>
<%= t.text_field :phone %>
<% end %>
<%= user.submit 'Confirm' %>
<% end %>
これが「ネストされた属性を受け入れない」ことを除いて、私の開発ログには次のように書かれています:
WARNING: Can't mass-assign protected attributes: teacher
関連しているかどうかはわかりませんが、フォームは teacher_attributes 配列などの内部にフィールドを生成していません - それは教師の中にあります。それが私の問題だと思いますが、フィールドをその中に入れる方法がわかりません。助けてください。
ありがとう!