Reputation: 6124
Is it possible to call helper methods from controller? If yes how to do this in Rails 3?
Upvotes: 29
Views: 20390
Reputation: 1198
This is working if some one wants to use ApplicationHelper method in other controllers or view just add this include ApplicationHelper
give below because all your controller derived from ApplicationController.
class ApplicationController < ActionController::Base
protect_from_forgery
include ApplicationHelper
end
Upvotes: 1
Reputation: 23770
You can either include the helper module in the controller, or define the helper as a controller method and mark it as a helper via helper_method :method_name
.
class FooHelper
def bar ... end
end
class QuxsController
include FooHelper
end
or
class QuxsController
private
def bar ... end
helper_method :bar
end
Upvotes: 30