I have setup a helper method within the application controller ie.
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
If I try to access to current_user variable within a view im getting an error
#code
Welcome <%=@current_user.first_name%>
#error
undefined method `first_name' for nil:NilClass
I know the session is good. Is this the correct was to access to current_user ?
Thanks for the help
这是一个方法,你试图访问一个实例变量,这样做:
Welcome <%= current_user.first_name%>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.