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?
Reload: This command will allow you to make changes to your code, and continue to use the same console session without having to restart. Simply type in the “reload!” command after making changes and the console will reload the session.
The console command lets you interact with your Rails application from the command line. On the underside, bin/rails console uses IRB, so if you've ever used it, you'll be right at home. This is useful for testing out quick ideas with code and changing data server-side without touching the website.
My guess would be that you're doing something like:
User
someMethod
on the instancereload!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With