Kevin
Kevin

Reputation: 1120

Help with Rails Seeds?

I have the following seeds.rb file:

initial_users = User.create(
[
{
    :first_name => "Joe", 
    :last_name => "Smith",
    :address1 => "123 Anywhere St.",
    :city => "San Francisco",
    :state => "CA",
    :zip => "12345",
    :phone => "123-456-1234",
    :password => "password"
},
{
    :first_name => "Jane", 
    :last_name => "Doe",
    :address1 => "123 Main St.",
    :city => "Los Angeles",
    :state => "CA",
    :zip => "12345",
    :phone => "123-345-4567",
    :password => "password"
}
])

But when I run rake db:seed, the rows don't show up in the database even though there isn't any error being reported? I even tried specifying RAILS_ENV=development but it still doesn't show up. What am I doing wrong?

Upvotes: 0

Views: 154

Answers (2)

jkozan
jkozan

Reputation: 1

Just a guess without seeing your model, but maybe you are missing the password_confirmation field and therefore your validations are failing

Upvotes: 0

Eimantas
Eimantas

Reputation: 49344

You should use create! which would raise an exception if any of the required attributes are missing. Other than that - i'd suggest random data generators to seed your data for development purposes. Or use some fixture replace for test purposes (check github for blueprints - my favorite).

Upvotes: 1

Related Questions