spring
spring copied to clipboard
To access new custom methods in Rails, we have to reload the spring
First, I add an admin? method to User


It works! Of course rails c will run spring in the background.
Now I'll change admin? to isAdmin?

I'll restart the server and try to access the isAdmin? method

Not working!

And admin? method still exist there.
To resolve this issue I have to reload the spring after exiting the console:

Then it's working!
Of course, I expect that I don't have to restart the spring to reload the model methods, I expect to just have to exit the console to have it reloaded.
You shouldn't have to restart Spring. You're seeing this issue because the old version of your User class is still in memory. Spring's not going to automatically restart if you update your User class like that. You can force Rails to refresh its version of User (and everything else) by running reload! in the Rails console. Then you should see isAdmin? show up.