ruby-on-railsruby-on-rails-3ruby-on-rails-3.2ruby-on-rails-4helpermethods

Helper methods to be used in Controllers AND Views in Rails


I understand I can put a helper method in a Helper class inside the helper folder in Rails. Then that method can be used in any view. And I understand I can put methods in the ApplicationController class and that method can be used in any controller.

Where's the proper place to put a method that is frequently used in both controllers and views?


Solution

  • You can put it in the controller and call:

    helper_method :my_method
    

    from the controller.