I'm just getting the hang of Rails console, and finding it useful for quickly testing methods in my classes. I know that I can make changes to my Models, then
> reload!
to grab those updates, but sometimes I'll find that it doesn't seem to reload my latest code. Does Rails cache code somewhere?
In a really simple pseudo example, I may have bad code on line 100:
100: u = User.alll
and in the Rails console, when I run this method, I might get an error similar to:
NoMethodError: undefined method `alll' for User:Class ... on line 100
then modify my code, fixing the error
100: u = User.all
then reload:
> reload!
and then, when calling the method in this class that has the correct code, it still will say
NoMethodError: undefined method `alll' for User:Class ... on line 100
When clearly, the error is fixed, and the offending line isn't even on line 100 anymore. Is there a way to force/hard-reset the "reload!" command?
My guess would be that you're doing something like:
User
someMethod
on the instance reload!
someMethod
on the existing instance and get the error again So you're calling the method on an instance that hasn't itself been reloaded. Its class has been reloaded, but the instance is already in memory - with bugs and all.
That would be my guess at least (not 100% sure).
Point is, if you create a new instance after the reload!
and call your method on that new instance, it should stop complaining.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.