Rails generate scaffold -> NameError: uninitialized constant

1.2k views Asked by At

I've got this stupid thing... I'm sure I just miss something obvious but yahoogling didn't solve the problem.

All I do is

rails new TestApp

and

cd TestApp
rails generate scaffold User name:string age:integer
bundle exec rake db:create
bundle exec db:migrate

which works fine.

But when I go to the IRB, there is no User!

u = User.first
    NameError: uninitialized constant User
    from (irb):3
    from /usr/bin/irb:12:in `<main>'

What's wrong here?

Cheers

2

There are 2 answers

4
davids On BEST ANSWER

Don't use irb, instead:

rails console

which will have every model of your project imported.

1
vlasits On

You haven't created a user and you are using plain old irb instead of rails console.

open a rails console and try:

User.create(:name => "Jimmy", :age => 14)

Then try

u = User.first