开发者

Scoped mass assignment and accepts_nested_attributes_for in Rails 3.1 not working?

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 => 'foo@blah.com', :email_confirmation => 'foo@foo.com'}}}, :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?


Issue and solution has been highlighted here.

In summary, an options hash must be passed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜