Rails 3.1 中的作用域质量分配和 Accepts_nested_attributes_for 不起作用?
使用 Rails 3.1 RC4。
我的用户模型具有以下内容:
has_many :emails, :dependent => :destroy
accepts_nested_attributes_for :emails
我的电子邮件模型具有以下内容:
belongs_to :user
attr_accessible :email, :email_confirmation, :as => :admin
在 Rails 控制台中:
User.first.update_attributes!({:artist_name => 'foo', :emails_attributes => {0 => {:email => '[email protected]', :email_confirmation => '[email protected]'}}}, :as => :admin)
我得到:
WARNING: Can't mass-assign protected attributes: email, email_confirmation
在我的电子邮件模型中,如果我删除 :as => :管理员。一切正常...
我应该为 accepts_nested_attributes_for
分配某种范围吗?有人知道如何解决这个问题吗?
Using Rails 3.1 RC4.
My User model has the following:
has_many :emails, :dependent => :destroy
accepts_nested_attributes_for :emails
My Email model has the following:
belongs_to :user
attr_accessible :email, :email_confirmation, :as => :admin
In Rails console:
User.first.update_attributes!({:artist_name => 'foo', :emails_attributes => {0 => {:email => '[email protected]', :email_confirmation => '[email protected]'}}}, :as => :admin)
I get:
WARNING: Can't mass-assign protected attributes: email, email_confirmation
In my Email model, if I remove :as => :admin
. Everything works...
Should I be assigning some kind of scope to accepts_nested_attributes_for
? Anyone know how this can be fixed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此处突出显示了问题和解决方案。
总之,必须传递一个选项哈希。
Issue and solution has been highlighted here.
In summary, an options hash must be passed.