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
to the view:
makes the +current_user+ and +logged_in?+ controller methods available
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) # def current_user(*args, &blk) controller.send(%(#{meth}), *args, &blk) # controller.send(:current_user, *args, &blk) end # end ruby_eval end end