2012-03-10 39 views
2

我使用魔法寶石進行驗證。我實際上沒有任何問題使用它的另一個項目,但我突然有一個奇怪的情況。我的模型是最初生成的巫術用戶模型,沒有任何attr_accessible。奇異attr_accessible在魔法

現在,我有一個種子文件,如:

users = { 

:hthought => { 
    :username => 'jkjhkj', 
    :email => 'hkjhk', 
    :crypted_password => 'hkjhjkhk', 
    :salt => 'hkjhjkhjh', 
    :password => '57667' 
} 

} 

users.each do |item, hash| 
    user = User.new(hash) 
    user.save! 
    hash.each do |attribute, value| 
     user.update_attribute(attribute, value) 
    end 
end 

當我執行這(與耙分貝:種子),我得到:

rake aborted! 
Can't mass-assign protected attributes: crypted_password, salt 

這是爲什麼?我真的不明白爲什麼我得到這個,因爲我的用戶模型中沒有attr_accessible。此外,我在另一個項目中使用完全相同的代碼,我從來沒有得到這個。

任何想法爲什麼?

回答

3

如果你看到魔術碼(https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model.rb#L82),你可以看到:

attr_protected @sorcery_config.crypted_password_attribute_name, @sorcery_config.salt_attribute_name 

所以這是很正常的這種保護的警告。

它在一年前增加了這個提交:https://github.com/NoamB/sorcery/commit/7c2e846bf5c084bea72eb6477e72daf0177d789e

+0

有趣,這是非常奇怪的,我沒有得到,在我的其他項目,非常非常怪異。 Thanx澄清。 – Spyros 2012-03-10 10:30:39

0

它可能是一個Rails的東西,而不是一個巫術的東西。如果您的新應用程序使用的是Rails 3.2.3,而您的舊應用程序低於該應用程序,那麼可能會導致attr_protected白名單的安全緊縮導致不同的行爲。此公告可能幫助:)

Rails error: Can't mass-assign protected attributes