0

使用Rails 3.1 RC4。Rails 3.1中的作用域批量賦值和accep_nested_attributes_for不起作用?

我的用戶模型有以下幾點:

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 => :admin。一切正常......

我應該將某種範圍分配給accepts_nested_attributes_for嗎?任何人都知道如何解決這個問題?

回答

0

問題和解決方案已突出顯示here

總之,必須傳遞選項散列。