Rails devise 插件已创建一个用户表。我怎样才能添加到它?
我使用 devise Rails 插件创建了以下内容。如何向用户表添加用户名字符串和唯一的 user_id 整数?使用devise时还需要创建users_controller吗?或者说没有必要?
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
评论中链接的指南将提供有关迁移的良好阅读材料,您将经常使用它。然而,简而言之,您可以通过执行以下操作来生成所需的迁移:
创建迁移后,您实际上可以通过执行以下操作来添加列:
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:
Once the migration is created, you can actually add the column by doing:
要回答你的最后一个问题,不,你不需要创建一个控制器来使用 devise,
尽管如果你想为用户提供索引或显示页面,你可以这样做。在这种情况下,您需要修改 路线一点
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