Rails console in production: NameError: uninitialized constant Rails console in production: NameError: uninitialized constant ruby-on-rails ruby-on-rails

Rails console in production: NameError: uninitialized constant


I had this problem and realized it happened after I made a tweak to one of my job files.What fixed it was restarting the spring loader. Just run

spring stop

Then the next time you run the rails console it should load things as normal.


I had this same issue, rewolf's answer above solved it for me temporarily.

Just to add to his answer:

After stopping the spring gem by running the command below

spring stop

You can also fix this issue permanently by upspringing (removing the spring gem from) your bin/ executables:

bin/spring binstub --remove --all

Or

spring binstub --remove --all

You can now run the command below to get into rails console in production

rails c --environment=production

Also, to avoid this from occurring in subsequent occasions endeavour to make sure that the spring gem is only present in development and test groups in your Gemfile.

Moreso, when you're in production make sure you always provide the --without development test argument to the bundle install command

bundle install --without development test

and not the usual or common

bundle install

Please note: As an indication, whenever you run the command rails c or rails console and you see the output below:

Running via Spring preloader in process 26651 WARNING: Spring is running in production. To fix this make sure the spring gem is only present in development and test groups in your Gemfile and make sure you always use bundle install --without development test in production

It's an indication that the spring gem is running in your production environment, and it should be stopped or removed entirely from your bin executables.

That's all.

I hope this helps