It's possible, although not very common, to use helper methods from controller actions. Before Rails 5, you had to include the helper module. In newer versions, you can use helpers in your controller with the helpers (plural) object.
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.
You can also try :
YourController.helpers.my_helper
for example :
> ApplicationController.helpers.content_tag(:div, "test")
=> "<div>test</div>"
This works with Rails 2, 3 and 4.1
please try to this
rails console
helper.any_method_of_helper(pass_argument)
example
helper.number_to_currency('123.45')
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