Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put Ruby helper methods for Rails controllers?

I have some Ruby methods certain (or all) controllers need. I tried putting them in /app/helpers/application_helper.rb. I've used that for methods to be used in views. But controllers don't see those methods. Is there another place I should put them or do I need to access those helper methods differently?

Using latest stable Rails.

like image 299
at. Avatar asked Nov 28 '12 19:11

at.


People also ask

Where do I put controller helper?

If you need to use a method in the application scope then I would suggest that you keep those methods inside the application controller and in order to use them inside views.. declare those as helper methods. The problem is that if there are many helper methods, ApplicationController can become unwieldy.

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.


1 Answers

You should define the method inside ApplicationController.

like image 127
Ryan Bigg Avatar answered Sep 21 '22 16:09

Ryan Bigg