Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling helper method from Rails 3 controller

Is it possible to call helper methods from controller? If yes how to do this in Rails 3?

like image 1000
Achaius Avatar asked Jan 18 '12 10:01

Achaius


People also ask

Can we use helper method in controller rails?

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.

How do you access the helper method in controller?

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.

How do you use the helper method in Ruby on Rails?

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.


1 Answers

 view_context.some_helper_method 
like image 125
Alexey Avatar answered Oct 19 '22 09:10

Alexey