EasierSaidThanDone
EasierSaidThanDone

Reputation: 1897

Rails generate scaffold -> NameError: uninitialized constant

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

Upvotes: 0

Views: 1253

Answers (2)

davids
davids

Reputation: 6371

Don't use irb, instead:

rails console

which will have every model of your project imported.

Upvotes: 8

vlasits
vlasits

Reputation: 2235

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

Upvotes: 2

Related Questions