I implemented Authlogic in my rails app which works and tests great. Users can login, logout, etc.
However, since I changed my methods in the users_controller to use the @current_user variable, none of my user methods or forms (other than “index” strangely…) work!
For example, this “Show” methods works and shows the user profile for any user (Note: I want to eventually restrict this to the currently logged in user somehow):
def show
@user = User.find(params[:id])
end
If I follow the show method as shown in the Authlogic rails cast and the official example to:
def show
@user = @current_user
end
I get all kinds of undefined method METHOD for nil:NilClass errors. It seems as the though the @current_user variable doesn’t contain any of the user’s information.
I assume the @current_user is pulling info from the current_user method as defined in the application controller below:
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
What am I missing? My hunch is that there is no mapping between the User object from the user model and the current_user method. Any help would be greatly appreciated!
Thanks in advance!
~Dan
Shouldn’t it be just
without the
@?