/ / Ruby on Rails + devise: Ako môžem vytvoriť prispôsobenú tabuľku používateľov pomocou devis rake db: migrate? - rubín-on-rails, vymyslieť, rubín-on-rails-3.1

Ruby on Rails + vymyslieť: Ako môžem vytvoriť tabuľku prispôsobených používateľov s devis rake db: migrovať? - rubín-na-koľajniciach, navrhnúť, ruby-on-rails-3.1

koľajnice generujú vymyslieť Užívateľ to mám =>

class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable

# t.encryptable
# t.confirmable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable


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

Chcem však vytvoriť tabuľku používateľov so stĺpcami používateľské meno, e-mail, heslo, rola, skupina, značka, created_at, modified_at.

Ako to môžem urobiť?

Je táto štruktúra správna, aby obsahoval používateľské meno, heslo, e-mail, skupinu, rolu, známku?

class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable

# t.encryptable
# t.confirmable
# t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both
# t.token_authenticatable

t.string :username
t.string :password
t.string :email
t.string :group
t.string :role
t.integer :mark

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

Čo sú tieto?

t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable

odpovede:

3 pre odpoveď č. 1

Môžete vykonať migráciu a pridať niektoré polia do tabuľky používateľov. Napríklad:

rails g add_fields_to_users username:string # as well as other fields you need

Potom, aby ste do tabuľky pridali stĺpce, postupujte takto:

rake db:migrate

Koncepcia už vygenerovala niektoré stĺpce, ktoré potrebujete, napríklad: e-mail, heslo, created_at, updated_at ...

Pri pridávaní rolí do vášho používateľského modelu by ste mali sledovať screencast cancan: railscasts a tiež si prečítajte doc aby som si mohol pozrieť nejaké novinky.

EDIT:

Ak chcete polia pridať manuálne, môžete ich pred spustením migrácie pridať do svojej metódy self.up:

def self.up
create_table(:users) do |t|

#...

t.rememberable
t.trackable

t.string :username
#... your other attributes here

end