This no longer works for rails version 2.0.2. An update for this generator is necessary
gem install login_generator
ruby script/generate login Account
mysql syntax:
CREATE TABLE users (
id int(11) NOT NULL auto_increment,
login varchar(80) default NULL,
password varchar(40) default NULL,
PRIMARY KEY (id)
);
postgres :
CREATE TABLE "users" (
"id" SERIAL NOT NULL UNIQUE,
"login" TEXT,
"password" TEXT,
PRIMARY KEY("id")
) WITH OIDS;
sqlite:
CREATE TABLE 'users' (
'id' INTEGER PRIMARY KEY NOT NULL,
'login' VARCHAR(80) DEFAULT NULL,
'password' VARCHAR(40) DEFAULT NULL
);
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :login, :string, :default => nil
t.column :password, :string, :default => nil
end
end
def self.down
drop_table :users
end
end
If you want to add a default user make sure to set password_confirmation in the migration (add this line in self.up)
User.create(:login => 'admin',
:password => 'password',
:password_confirmation => 'password')
require 'login_system'
class ApplicationController < ActionController::Base
include LoginSystem
model :user
end
def delete
if params['id'] && @session['user'] && @session['user'].id == params['id']
before_filter :login_required
class AllMySecretsController < ApplicationController
before_filter :login_required
def show_one_secret
...
end
end
class AllMySecretsController < ApplicationController
before_filter :login_required, :except => [ :show_one_secret ]
def show_one_secret
...
end
end
and voila! you can start adding users.
Much info taken from Login Generator’s README_LOGIN1 You can call the login controller whatever you want (Account is just an example). However to change the login system to use a model other than “User” (for instance “MyModel”) you will need to modify the following:
category: Howto
Bath and Shower
Fragrance
Gift Sets
Hair Care
Makeup
Men’s Grooming
Shaving and Hair Removal
Skin Care
Tools and Accessories
Computers – Computer Add-Ons
Computers – Desktops
Computers – Handhelds & PDAs
Computers – Notebooks
Baby Diapering
Baby Feeding
For Moms
Baby Furniture
Baby Gear
Baby Gifts
Baby Health & Baby Care
Nursery Décor
Potty Training
Baby Safety
Baby Strollers
This no longer works for rails version 2.0.2. An update for this generator is necessary
gem install login_generator
ruby script/generate login Account
mysql syntax:
CREATE TABLE users (
id int(11) NOT NULL auto_increment,
login varchar(80) default NULL,
password varchar(40) default NULL,
PRIMARY KEY (id)
);
postgres :
CREATE TABLE "users" (
"id" SERIAL NOT NULL UNIQUE,
"login" TEXT,
"password" TEXT,
PRIMARY KEY("id")
) WITH OIDS;
sqlite:
CREATE TABLE 'users' (
'id' INTEGER PRIMARY KEY NOT NULL,
'login' VARCHAR(80) DEFAULT NULL,
'password' VARCHAR(40) DEFAULT NULL
);
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :login, :string, :default => nil
t.column :password, :string, :default => nil
end
end
def self.down
drop_table :users
end
end
If you want to add a default user make sure to set password_confirmation in the migration (add this line in self.up)
User.create(:login => 'admin',
:password => 'password',
:password_confirmation => 'password')
require 'login_system'
class ApplicationController < ActionController::Base
include LoginSystem
model :user
end
def delete
if params['id'] && @session['user'] && @session['user'].id == params['id']
before_filter :login_required
class AllMySecretsController < ApplicationController
before_filter :login_required
def show_one_secret
...
end
end
class AllMySecretsController < ApplicationController
before_filter :login_required, :except => [ :show_one_secret ]
def show_one_secret
...
end
end
and voila! you can start adding users.
Much info taken from Login Generator’s README_LOGIN1 You can call the login controller whatever you want (Account is just an example). However to change the login system to use a model other than “User” (for instance “MyModel”) you will need to modify the following:
category: Howto
Bath and Shower
Fragrance
Gift Sets
Hair Care
Makeup
Men’s Grooming
Shaving and Hair Removal
Skin Care
Tools and Accessories
Computers – Computer Add-Ons
Computers – Desktops
Computers – Handhelds & PDAs
Computers – Notebooks
Baby Diapering
Baby Feeding
For Moms
Baby Furniture
Baby Gear
Baby Gifts
Baby Health & Baby Care
Nursery Décor
Potty Training
Baby Safety
Baby Strollers