Is it possible to call helper methods from controller? If yes how to do this in Rails 3?
In Rails 5, by using the new instance level helpers method in the controller, we can access helper methods in controllers. This removes some of the drawbacks of including helper modules and is much cleaner solution.
In the first version, you can just use html_format - you only need MyHelper. html_format in the second. This does not work when the helper method you want to use make use of view methods such as link_to . Controllers don't have access to these methods and most of my helpers use these methods.
A Helper method is used to perform a particular repetitive task common across multiple classes. This keeps us from repeating the same piece of code in different classes again and again. And then in the view code, you call the helper method and pass it to the user as an argument.
view_context.some_helper_method
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