instance method
helper_method
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
helper_method(*methods)
Declare a controller method as a helper. For example, the following makes the current_user controller method available to the view:
class ApplicationController < ActionController::Base helper_method :current_user, :logged_in? def current_user @current_user ||= User.find_by_id(session[:user]) end def logged_in? current_user != nil end end
In a view:
<% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
Parameters
-
methodsrest
Source
# File actionpack/lib/action_controller/helpers.rb, line 163
def helper_method(*methods)
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
def #{method}(*args, &block) # def current_user(*args, &block)
controller.send(%(#{method}), *args, &block) # controller.send(%(current_user), *args, &block)
end # end
end_eval
end
end
Defined in actionpack/lib/action_controller/helpers.rb line 163
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::Helpers::ClassMethods