I am using authlogic for authentication in my rails app. I need to be able to call a method for the current_user when they sign in but it’s returning nil.
In my user_sessions_controller.rb
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
current_user.increment_login_count_for_current_memberships!
flash[:notice] = 'Sign in successful.'
redirect_to root_path
else
render action: "new"
end
end
And it’s returning…
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `increment_login_count_for_current_memberships!' for nil:NilClass
I’ve seen a similar problem here Not able to set a current_user using Authlogic on Rails 3.0.1 where the answer was to disable basic_auth, but I am using basic_auth for my admin side of the app so I cannot simply disable it.
-
Why can’t I call the
current_userhere? -
If I can’t call
current_userhere, is there a way to set it?
I still don’t know why I cannot call
current_useror@current_userhere. But I found two ways to call the current_user here in the controller code…and
If anyone wants to shed some light on why I can’t call
current_userhere, I’ll happily award you the bounty 🙂