Astm
Astm

Reputation: 1710

rails seed DB file

Guys now i want to add just data in my users Table just for test with it so I'm trying from use this code

users.create(:name => "admin",:user => "admin",:pass=> "123")

in the seed file then when it trying to run rake db:seed

it always gave me error

my table structure was

create_table :users do |t|
      t.string :name
      t.string :user
      t.string :pass

      t.timestamps

so i want to know what is the best way to add data to the DB using the seed file

Upvotes: 0

Views: 298

Answers (2)

Astm
Astm

Reputation: 1710

Its work well now by Using the command

Users.create(:name =>"admin",:user =>"admin",:pass=>"123")

then run the command rake db:seed on the screen command then restart the server

the I can see the data from the screen command by typing the command

rails c
Users.all

my error was i typed

users.create(:name =>"admin",:user =>"admin",:pass=>"123")

not

Users.create(:name =>"admin",:user =>"admin",:pass=>"123")

the model name must be capital "Users" not "users"

thanks guys for tying to help me :)

Upvotes: 0

bjhaid
bjhaid

Reputation: 9752

change

users.create(:name => "admin",:user => "admin",:pass=> "123")

to

User.create(:name => "admin",:user => "admin",:pass=> "123")

Model names in rails are singular, while the table name is plural

Upvotes: 3

Related Questions