NameError: uninitialized constant Object::User
Asked Answered
P

2

8

I searched the other posts that had this issue and could not find one that fixed my particular issue. My irb is going crazy. I am trying to change user roles in my database but I can't even get to my users!

irb(main):001:0> User.all
NameError: uninitialized constant Object::User
        from (irb):1
        from c:/Ruby192/bin/irb:12:in `<main>'

It was working fine, stopped working, was fine, and now stopped again. I have a User model and users added. I cannot pinpoint the issue. Let me know what code you need to see. Thanks!

Preengage answered 12/5, 2011 at 16:23 Comment(0)
V
32

You should run

ruby script/console # Rails < 3

or

rails c  # Rails 3.x

But not (I believe you've just run this)

irb
Valid answered 12/5, 2011 at 16:26 Comment(3)
You mean console, not server.Abelmosk
Yep, that worked. Thanks a lot. What a stupid mistake I made. I was told that you can go with either one and it will take you to the same place. Not true.Preengage
or in my case if you want to start it in production mode you can run $rails c productionHousebreaker
A
8

Make sure you're actually using the rails console command rather than just running irb in your project folder.

Abelmosk answered 12/5, 2011 at 16:26 Comment(2)
Is there a good reason why to use rails console rather then irb? Is it possible to access project model Object via irb? So far I'm getting this "NameError: uninitialized constant ...".Pulsar
irb won't load your Rails environment at all, you have to use the rails console for that.Abelmosk

© 2022 - 2024 — McMap. All rights reserved.