I think this has something to do with you overriding that "self.create" method on UserSession. If you have to override it, try invoking super(user) within it so as to make sure the actual authlogic create method gets run into Authlogic::Session::Base.
Regardless of the above, I think this is definitely a problem: current_user = @user_session.record current_user.save! Be aware that the way this is written, you are simply declaring a local variable - not actually setting "current_user" as on the controller instance. To do that you need to explicitly use self.current_user: self.current_user = @user_session.record self.current_user.save! That being said, I don't know authlogic well enough to know if you can just set self.current_user and expect things to work, which is why you may need to call super(user) within that overridden create method. -- Ben Hughes http://benhugh.es/ On Tue, Feb 8, 2011 at 10:43 PM, Guyren Howe <[email protected]> wrote: > I do this: > > class UserSessionsController < ApplicationController > > def create > > @user = User.where(login: params['user_session']['login']).first > @user_session = UserSession.create params[:user_session], @user, > params[:user_session][:organization_id] > if @user_session.errors.empty? > > current_user = @user_session.record > > current_user.save! > > > redirect_back_or_default user_info_path > > else > > render action: :new > > end > > end > > end > > > class UserSession < Authlogic::Session::Base > > def self.create params, user, org_id > > result = new params > result.user = user > result.org_id = org_id.to_i > > result > > end > > end > > but then when I do this during the redirect after successfully supposedly > creating @user_session: > > class ApplicationController < ActionController::Base > > before_filter :require_user > > 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 > > def require_user > unless current_user > store_location > flash[:notice] = "You must be logged in to access this page" > redirect_to new_user_session_url > return false > end > end > > end > > UserSession.find isn’t finding anything. > > I’m using the default cookie session. I dare say I’m doing something > monumentally simple and stupid, but I just can’t see it right now. Can > anyone else? > > -- > SD Ruby mailing list > [email protected] > http://groups.google.com/group/sdruby -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
