我无缘无故地收到 UnkownAttributeError,我的模型似乎设置正确......
学校.rb
class School < ActiveRecord::Base
attr_protected :id, :created_at, :updated_at
#relationships
has_many :users
accepts_nested_attributes_for :users
end
我的 School 模型曾经有以下内容,但它为用户字段产生了 MassAssignmentSecurity 错误:
attr_accessible :country, :name, :state_or_province, :users_attributes
用户.rb
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :instructor_id, :first_name, :last_name, :school_id
#relationships
belongs_to :school
end
新的.html.haml
= simple_form_for @school do |f|
.well
= f.input :name, :as => :hidden
= f.input :country, :as => :hidden
= f.input :state_or_province, :as => :hidden
.well
= f.simple_fields_for @school.users.build do |user_form|
= user_form.input :first_name, :required => true
= user_form.input :last_name, :required => true
= user_form.input :username, :required => true
...
= f.button :submit, "Next"
注意:@school
正在从上一页收集的会话信息中填充我的新操作,我正在制作一个多步骤表单。学校数据完全有效,如果我要删除用户表单,保存学校不会有任何问题。
我在创建操作中收到的特定错误消息:
SchoolsController#create 中的 ActiveRecord::UnknownAttributeError
未知属性:用户
发送的参数看起来有点像这样:
{"school"=>{"name"=>"Elmwood Elementary", "country"=>"38", "state_or_province"=>"448", "user"=>{"first_name"=>"joe", "last_name"=>"asdas", "username"=>"asasdads", "email"=>"asdasd@sdas.ca", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED ]"}}, "提交"=>"下一步"}
这可能是 Devise 或 simple_form 的错误吗?我正在使用 Rails 3.2.3