2012-12-17 50 views
-2

在我的應用程序中,我需要做兩種方式 - 登錄系統: 1)用戶 - 只爲網站的用戶部分,包含用戶的信息,它的登錄數據等... 2 )管理員 - 網站管理員部分的另一個模型。寶石設計集多用戶模型系統

但如何做到這一點? 現在我只有第一部分,我的移民:

class DeviseCreateUsers < ActiveRecord::Migration 
    def self.up 
    create_table(:users) do |t| 
    ## Database authenticatable 
    t.string :email, :null => false, :default => "" 
    t.string :encrypted_password, :null => false, :default => "" 

    ## Recoverable 
    t.string :reset_password_token 
    t.datetime :reset_password_sent_at 

    ## Rememberable 
    t.datetime :remember_created_at 

    ## Trackable 
    t.integer :sign_in_count, :default => 0 
    t.datetime :current_sign_in_at 
    t.datetime :last_sign_in_at 
    t.string :current_sign_in_ip 
    t.string :last_sign_in_ip 

    ## Encryptable 
    # t.string :password_salt 

    ## Confirmable 
    #t.string :confirmation_token 
    #t.datetime :confirmed_at 
    #t.datetime :confirmation_sent_at 
    #t.string :unconfirmed_email # Only if using reconfirmable 

    ## Lockable 
    #t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts 
    #t.string :unlock_token # Only if unlock strategy is :email or :both 
    #t.datetime :locked_at 

    ## Token authenticatable 
    t.string :authentication_token 

    t.timestamps 
    end 

    add_index :users, :email, :unique => true 
    add_index :users, :reset_password_token, :unique => true 
    #add_index :users, :confirmation_token, :unique => true 
    #add_index :users, :unlock_token, :unique => true 
    add_index :users, :authentication_token, :unique => true 
    end 

    def self.down 
    drop_table :users 
    end 
end 

和路由:

devise_for :users 

但如何添加第二個管理員登錄的一部分?

+0

有人明智地閱讀[文檔](https://github.com/plataformatec/devise#configuring-multiple-models)。如果你想獲得幫助,也不要這麼粗魯。 – Hauleth

回答

1

你有3種選擇:

  1. 添加字符串字段type你的表,並從User模型推導(管理員和用戶將具有相同的登錄路由)。
  2. 添加布爾字段admin並使用CanCan gem。
  3. 運行rails g devise admin並有單獨的管理模式。

您選擇的方式取決於您的應用程序結構。