[Rails] Re: undefined method current_user issue
> At the top of your controller, you'll want to add
> helper_method :current_user
Thanks for response, but I place this in application controller:
helper_method :current_user
private
def require_login
unless logged_in?
flash[:error] = "You must be logged in to access this section"
redirect_to login_path
end
end
def logged_in?
!!current_user
end
def current_user
@current_user ||= session[:user_id] && User.find(session[:user_id])
end
And now because all my contorllers inherit from it, I get undefined
method current_user on all the pages, even though current user is
clearly defined.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home