I'm calling helper methods from the Rails console in Rails 3 like this:
>> helper.my_method(parameter)
>> #=> some result
However, if I change the helper method the changes are not reflected when I call the same method again. I have to exit
and run rails console
in order to see the changes to the helper method take effect.
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.
In Rails 5, by using the new instance level helpers method in the controller, we can access helper methods in controllers.
A helper is a method that is (mostly) used in your Rails views to share reusable code. Rails comes with a set of built-in helper methods. One of these built-in helpers is time_ago_in_words . This method is helpful whenever you want to display time in this specific format.
Basically helpers in Rails are used to extract complex logic out of the view so that you can organize your code better.
Actually, helper
is an instantiated object that memoizes the ApplicationController helpers, which will not be reloaded when you call reload!
, at least in Rails 4. You can work around this by calling ApplicationController.helpers.my_method(parameter)
in the console. You will still need to use reload!
when you edit the helper, but it will reload unlike helper
.
You just need to run reload!
and most classes will be reloaded, including your helpers.
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