这是我的用户模型:
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 数组或任何东西中生成字段 - 它在教师内部。我猜这就是我的问题所在,但我不知道如何让它把字段放在里面。请帮忙。
谢谢!