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_开发者_C百科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
It's a method, you're trying to access an instance variable, do it like this:
Welcome <%= current_user.first_name%>
精彩评论