3
我已經在應用程序控制器內設置了一個輔助方法。Rails 3 helper_method
class ApplicationController < ActionController::Base
# Helpers
helper_method :current_user
# Private Methods
private
def current_user
@current_user ||= Tester.find(session[:user_id]) if session[:user_id]
end
end
如果我試圖訪問一個視圖IM中CURRENT_USER變量得到一個錯誤
#code
Welcome <%[email protected]_user.first_name%>
#error
undefined method `first_name' for nil:NilClass
我知道會議是好的。這是正確的訪問current_user?
感謝您的幫助