开发者

Scoped mass assignment and accepts_nested_attributes_for in Rails 3.1 not working?

开发者 https://www.devze.com 2023-03-12 17:11 出处:网络
Using Rails 3.1 RC4. My User model has the following: 开发者_开发知识库has_many :emails, :dependent => :destroy

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

精彩评论

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