How do I set up a method that I want accessible from all controllers?
Sticking the method in application_helper just makes it available to the views
How do I set up a method that I want accessible from all controllers?
Sticking the method in application_helper just makes it available to the views
You can include ApplicationHelper
in your controllers (or base ApplicationController) to make the helper methods available.
You can also include the following line in your ApplicationController to include all helpers:
helper :all
Stick it into lib
. Helpers are meant to be used in views; if you have application-specific libraries (and by "libraries" I mean any code that your application uses, and by "application-specific" anything that doesn't belong into vendor
), lib
is the place to go.
You can add the method to ApplicationController
. All the other controllers subclass ApplicationController
, so will be able to call the method.
You'll want to make the method protected
so that it is only visible to subclasses and isn't available as a web-accessible action.