The following shows a typical Rails migration for creating the users, roles and role_users table for the acts_as_authenticated plugin. Note that an initial admin user with a default password is added:
class CreateRolesAndUsers < force =""> true do |t| t.column :login, :string t.column :email, :string t.column :crypted_password, :string, :limit => 40 t.column :salt, :string, :limit => 40 t.column :created_at, :datetime t.column :updated_at, :datetime t.column :remember_token, :string t.column :remember_token_expires_at, :datetime end create_table :roles, :force => true do |t| t.column :name, :string, :limit => 40 t.column :authorizable_type, :string, :limit => 30 #t.column :authorizable_id, :integer t.column :created_at, :datetime t.column :updated_at, :datetime end create_table :roles_users, :force => true do |t| t.column :user_id, :integer t.column :role_id, :integer t.column :created_at, :datetime t.column :updated_at, :datetime end #add user "demo" as admin role = Role.new(:name => "admin", :authorizable_type => "admin") role.save user = User.new(:login => "demo", :email => "none@none.com", :password => "demo", :password_confirmation => "demo") user.save roleuser = RolesUser.new(:user_id => 1, :role_id => 1) roleuser.save end def self.down drop_table :roles_users drop_table :roles drop_table "users" end end
Comments