Is there a Rails Console command (Rails 3+) to reload changed code?

Ruby on-RailsRubyRuby on-Rails-3

Ruby on-Rails Problem Overview


I am playing with the console, I change some model code and now I want to test it. I normally re-start the console. Is there a quicker way? Maybe a console command to reload the model code?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Of course, simply type:

reload!

Solution 2 - Ruby on-Rails

You need to call reload!

This command will clear the loaded constants that have been loaded and will load them as they're referenced in the console.

If you have old objects from before the reload! you will need to call reload on these individual objects or find new objects and work with them if you want to try out the new method.

Solution 3 - Ruby on-Rails

You can type reload!.

I think it's important to note that reload! doesn't reinitialize rails console session existing objects, it just reloads the code:
https://stackoverflow.com/a/10465369/9185715
So, if you have instantiated any objects in the console, they won't be reinitialized.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMatteo MelaniView Question on Stackoverflow
Solution 1 - Ruby on-RailsapneadivingView Answer on Stackoverflow
Solution 2 - Ruby on-RailskarlingenView Answer on Stackoverflow
Solution 3 - Ruby on-RailsMaxim BerdnikovView Answer on Stackoverflow