Authlogic auto login fails on registration with STI User model
- by Wei Gan
Authlogin by default is supposed to auto login when the user's persistence token changes. It seems to fail in my Rails app. I set up the following single table inheritance user model hierarchy:
class BaseUser < ActiveRecord::Base
end
class User < BaseUser
acts_as_authentic
end
create_table "base_users", :force => true do |t|
t.string "email"
t.string "crypted_password"
t.string "persistence_token"
t.string "first_name"
t.string "last_name"
t.datetime "created_at"
t.datetime "updated_at"
t.string "type"
end
To get auto login to work, I need to explicitly log users in in my UsersController:
def create
@user = User.new(params[:user])
if @user.save
UserSession.create(@user) # EXPLICITLY LOG USER IN BY CREATING SESSION
flash[:notice] = "Welcome to Askapade!"
redirect_to_target_or_default root_url
else
render :action => :new
end
end
I was wondering if it's anything to do with STI, or that the table is named "base_users" and not "users". I set it up before without STI and it worked so I'm wondering why once I put in place this hierarchy, it fails. Thanks!