rails devise plugin has created a users table. How can I add to it?
I created the following with the devise rails plugin. How do I go about adding a username string and unique user_id integer to the users table? Also is it necessary to create a users_controller when using devise? Or is that not necessary?
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
The guide linked to in the comments will provide good reading on migrations, which you will come to use very frequently. In short, however, you can generate the migration needed by doing:
rails g migration add_username_to_users username:string
Once the migration is created, you can actually add the column by doing:
rake db:migrate
To answer to your last question, no, you don't need to create a controller to use devise
Although you could do if you wanted to have an index or show page for your users. In which case you would need to modify your routes a little
精彩评论