Saturday, June 19, 2010

Rails 3 and Authlogic

A geeky FYI...for those who are hoping to use Authlogic with Rails 3, there are a few hangups. Authlogic 3 will support Rails 3, but until then, for those of you trying to figure out how to get Authlogic to work with Rails 3, you will want to use scrum8/authlogic from github which is a functional branch for Rails 3.

You can use this branch of Authlogic by doing the following thing:

1. In your "Gemfile" put the following:

gem 'authlogic', :git => "http://github.com/scrum8/authlogic.git"

2. Run the following from your command line:

bundle install

(This will bundle the scrum8/authlogic branch into your local application)

3. Follow the README directions midway down at the authlogic_example page:

http://github.com/binarylogic/authlogic_example

4. Rather than using 'script/generate session user_session' you will have to manually create user_session.rb in your models folder with the following content:

class UserSession < Authlogic::Session::Base
end

5. You will also want to create a migration file for UserSessions which you can do by running 'rails g migration UserSessions' then make sure the following content is present:

class CreateUserSessions < ActiveRecord::Migration
def self.up
create_table :user_sessions do |t|
t.string :username
t.string :password

t.timestamps
end
end

def self.down
drop_table :user_sessions
end
end

1 comment:

Kev said...

Thanks for this post. It works except for one thing:

"4. Rather than using 'script/generate session user_session' you will have to manually create user_session.rb in your models folder with the following content:"

should be "create_user_session" instead of "user_session".