When I run rake db:seed
in my Rails 3 application I get the error:
rake aborted!
undefined method 'find_or_create_by_first_name_and_last_name_and_role_and_email_and_password_and_password_confirmation'
Below are my create_users.rb
and seeds.rb
files respectively. Why isn't the find_or_create_by_*
method being dynamically created?
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 :persist开发者_C百科ence_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(...)
According to the 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)
I'm guessing password
and password_confirmation
are protected attributes.
You are missing "and" between role and email
User.find_or_create_by_first_name_and_last_name_and_role_and_email_and_password_and_password_confirmation(...)
精彩评论