module AbstractController::Helpers::ClassMethods
def helper_method(*meths)
* method[, method] - A name or names of a method on the controller
==== Parameters
<% if logged_in? -%>Welcome, <%= current_user.name %><% end -%>
In a view:
end
end
current_user != nil
def logged_in?
end
@current_user ||= User.find_by_id(session[:user])
def current_user
helper_method :current_user, :logged_in?
class ApplicationController < ActionController::Base
makes the +current_user+ controller method available to the view:
Declare a controller method as a helper. For example, the following
def helper_method(*meths) meths.flatten! self._helper_methods += meths meths.each do |meth| _helpers.class_eval <<-ruby_eval, __FILE__, __LINE__ + 1 def #{meth}(*args, &blk) controller.send(%(#{meth}), *args, &blk) end ruby_eval end end