spring icon indicating copy to clipboard operation
spring copied to clipboard

To access new custom methods in Rails, we have to reload the spring

Open imam opened this issue 7 years ago • 1 comments

First, I add an admin? method to User

image

image

It works! Of course rails c will run spring in the background.

Now I'll change admin? to isAdmin?

image

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

image

Not working!

image

And admin? method still exist there.

To resolve this issue I have to reload the spring after exiting the console:

image

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.

imam avatar Jul 27 '18 08:07 imam

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.

mcmire avatar Aug 09 '18 00:08 mcmire