Rails: NameError: uninitialized constant

Rails: NameError: uninitialized constant

Some things to try:

  1. Restart the rails console; changes to your models will only get picked up by a rails console that is already open if you do > reload! (although I have found this to be unpredictable), or by restarting the console.

  2. Is your model file called phone_number.rb and is it in /app/models?

  3. You should double-check the –sandbox option on your rails console command. AFAIK, this prevents changes. Try it without the switch.

I was getting the error:

NameError: uninitialized constant

Then I noticed that I had accidentally created a plural model so I went back and renamed the model file to singular and also changed the class name in the model file to singular and that solved it.

Rails: NameError: uninitialized constant

I started having this issue after upgrading Rails 5.1 to 5.2
I got it solved with:

spring stop
spring binstub --all
spring start
rails s

Leave a Reply

Your email address will not be published.