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_user
here?If I can't call
current_user
here, is there a way to set it?