2011-04-02 20 views
0

当我在我的Rails运行rake db:seed 3应用程序,我得到的错误:无法种子数据的Authlogic

rake aborted! 
undefined method 'find_or_create_by_first_name_and_last_name_and_role_and_email_and_password_and_password_confirmation' 

下面分别是我的create_users.rbseeds.rb文件。为什么find_or_create_by_*方法不是动态创建的?

def self.up 
    create_table :users do |t| 
     t.string :first_name, :null => false 
     t.string :last_name, :null => false 
     t.string :role, :null => false 
     t.string :email, :null => false 
     t.string :crypted_password, :null => false 
     t.string :password_salt, :null => false 
     t.string :persistence_token, :null => false 
     t.string :current_login_ip 
     t.string :last_login_ip 
     t.datetime :current_login_at 
     t.datetime :last_login_at 

     t.timestamps 
    end 
    end 

User.find_or_create_by_first_name_and_last_name_and_role_and_email_and_password_and_password_confirmation(...)

回答

2

之间。根据docs

This dynamic finder is called with find_or_create_by_ and will return the object if it already exists and otherwise creates it, then returns it. Protected attributes won’t be set unless they are given in a block. (emphasis mine)

我猜passwordpassword_confirmation是受保护的属性。

+0

感谢您指出处理受保护属性时的限制。更改为'User.create(...)'解决了问题。 – DaneS 2011-04-03 20:26:58

0

你缺少 “和” 角色和电子邮件

User.find_or_create_by_first_name_and_last_name_and_role_and_email_and_password_and_password_confirmation(...)

+0

对不起,失踪的“和”是我的帖子中的一个错字。它正确地写在我的seeds.rb文件中,但是出现错误。 – DaneS 2011-04-02 15:46:21