adding data from rails seed DB file

29 views
Skip to first unread message

Astm Ali

unread,
Feb 2, 2014, 11:01:51 AM2/2/14
to rubyonra...@googlegroups.com
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 the error [undefined local variable or method 'users'
for main : object]

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

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Feb 2, 2014, 11:13:54 AM2/2/14
to rubyonra...@googlegroups.com
On 2 February 2014 16:01, Astm Ali <li...@ruby-forum.com> wrote:
> 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")

Try User.create it is a class method of the model.

Colin

>
> in the seed file then when it trying to run rake db:seed
>
> it always gave me the error [undefined local variable or method 'users'
> for main : object]
>
> 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
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9d990ac9cb1fc814a856021ed64b166f%40ruby-forum.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Astm Ali

unread,
Feb 2, 2014, 12:04:48 PM2/2/14
to rubyonra...@googlegroups.com
when i used the command
User.create(:name => "admin",:user => "admin",:pass=> "123")
it gives me the same error
but then i used the command
Users.create(:name => "admin",:user => "admin",:pass=> "123")
it not gave me any error
now when i tried to use the command Rails c then Users.All
to show the data from the command screen
it gave me the error ( unintialized constant Ur)

Colin Law

unread,
Feb 2, 2014, 1:00:58 PM2/2/14
to rubyonra...@googlegroups.com
On 2 February 2014 17:04, Astm Ali <li...@ruby-forum.com> wrote:
> when i used the command
> User.create(:name => "admin",:user => "admin",:pass=> "123")
> it gives me the same error
> but then i used the command
> Users.create(:name => "admin",:user => "admin",:pass=> "123")
> it not gave me any error

What is the model name in user.rb? It should be User not Users.

Colin


> now when i tried to use the command Rails c then Users.All
> to show the data from the command screen
> it gave me the error ( unintialized constant Ur)
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eda31d7813311d395706c0d967414601%40ruby-forum.com.
Reply all
Reply to author
Forward
0 new messages