Monday, April 17, 2006

The LoginGenerator gem is a good way to add login capability to your Ruby on Rails application. Here's a RoR wiki entry on LoginGenerator

I found it easy to install.

First, install the gem:

gem install login_generator


Then, generate the controller with:

script/generate login Account


Then change your ApplicationController to look like:

require_dependency "login_system"

class ApplicationController < ActionController::Base
include LoginSystem
model :user


Then, for Postgres, add a "users" table with:

CREATE TABLE users (
id SERIAL PRIMARY KEY,
login VARCHAR(80),
password VARCHAR(40)
) WITH OIDS;


Finally, add the following line to any controller you want people to have to login to get to:

before_filter :login_required