viewでもcontrollerのメソッドを使いたいときはhelper_methodを使う
controllerでhelper_methodを定義
application_controller.rb
class ApplicationController < ActionController::Base
helper_method :current_user, :logged_in?
private
def current_user
return unless session[:user_id]
@current_user ||= User.find(session[:user_id])
end
def logged_in?
!!session[:user_id]
end
end
viewで呼び出し
home.html.erb
<%= current_user %>