Reputation: 1454
For the life of me, I can't get this to work. I have an application where each account has a unique subdomain. Within that account, users have a unique username but the username may not be unique across the application as a whole.
def create
@user_session = @current_account.user_sessions.new(params[:user_session])
@user = @current_account.users.find_by_username_or_email(params[:user_session][:username])
if @user_session.save
flash[:notice] = "Welcome back #{current_user.first_name}"
if @user_session.user.account.is_new? && !@current_account.stop_wizard?
redirect_to :controller => "site", :action => "welcome", :id => "one"
else
redirect_to dashboard_url
end
else
render :action => :new
end
end
This seems to fail on the if @user_session.save
line because it validates against the first instance of the username within the database and not against the username that is scoped to the current account.
Any advice would be appreciated.
Thanks
Robin
Upvotes: 0
Views: 173
Reputation: 1454
The with scope option when creating my session was the answer.
Upvotes: 1