How to call ApplicationController methods from ApplicationHelper How to call ApplicationController methods from ApplicationHelper ruby ruby

How to call ApplicationController methods from ApplicationHelper


Use helper_method.

By default, methods in ApplicationController are only accessible inside the Controllers.

Add a method to the ApplicationController and expose it as a helper method with helper_method:

class ApplicationController < ActionController::Base  helper_method :foo  def foo    "bar"  endend

Now the foo method is accessible to both Controllers and Views.


If the issue is to make methods in ApplicationHelper available in all controllers, why not add a line

include ApplicationHelper

to the ApplicationController file?