I have the standard current_user methods in my application_controller.
def current_user_session
return @current_user_session if defined?
(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session &&
current_user_session.record
end
In my UserSessionController create method, I checked for registration_complete? (simply a check on a value of a column, which works fine) and then redirect the user to the user edit page if the registration is not complete. When I debug this, I can see that the attempted_record for the @user_session object exists and it's pointing to the correct user, but the current_user method in the redirect_to edit_user_path(current_user), always returns nil.
What's going wrong here?
def create
@user_session = UserSession.new(params[:user_session])
# uses a block to prevent double render error...
# because oauth and openid use redirects
@user_session.save do |result|
if result
flash[:notice] = "Login successful!"
if @user_session.new_registration?
logger.info "Session controller : new
registration"
logger.info "Complete -
#{@user_session.registration_complete?}"
flash[:notice] = "Please review profile"
redirect_to edit_user_path(current_user)
else
if @user_session.registration_complete?
logger.info "Session Controller - registration
complete"
else
flash[:notice] = "Please complete profile"
logger.info "Session Controller - registration
not complete"
redirect_to edit_user_path(current_user)
#current_user nil here
end
end
redirect_to current_user ? profile_url(current_user) :
login_url
else
if @user_session.errors.on(:user)
# if we set error on the base object, likely it's
because we didn't find a user
render :action => :confirm
else
render :action => :new
end
end
end
end