第一代后修改设备模块
我正在学习rails。我发现 Devise 非常适合快速、无缝地启动和运行身份验证,但我确实有一个问题。
首次运行 Devise 生成器后如何更改模块(例如,rails g devise User)?默认情况下进行以下迁移:
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
# 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
end
如果我已经运行此迁移,我如何在稍后阶段添加/删除其中一些模块?例如,也许我想向现有的用户模型添加可锁定功能。我了解如何在模型和 devise.rb 中进行更改,但我不确定如何处理迁移。
抱歉,如果答案已经在这里,我已经在这里和谷歌中搜索了几个小时,但找不到任何东西。也许我正在寻找错误的东西。
预先感谢!
杰森
附:我正在使用
Rails 3.0.0
设计1.1.3
I'm in the process of learning rails. I've found Devise to be great with getting authentication up and running quickly and seamlessly but I do have one question.
How do I change the modules after the first run of the Devise generator (e.g. rails g devise User)? This defaults with the following migration:
def self.up
create_table(:users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
# 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
end
If I've run this migration, how do I add/remove some of those modules at a later stage? E.g. Maybe I want to add lockable to an existing User model. I understand how to make the changes in the model and devise.rb
but I'm not sure what to do with the migrations.
Apologies if the answer is here already, I've trawled for a couple of hours here and in google and couldn't find anything. Maybe I'm searching for the wrong thing.
Thanks in advance!
Jason
ps. I'm using
rails 3.0.0
devise 1.1.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我正在寻找同一问题的答案,幸运的是,碰巧坐在知道如何做的人旁边。
以下是通过迁移脚本更新用户模型以包含可确认模块的示例(使用 'railsgenerate migration add_confirmable_to_users' 生成的骨架脚本文件):
I was looking for answer to the same question, and luckily, happened to be sitting next to someone who knew how to do it.
Here is the example of updating the users model to include confirmable module through a migration script (the skeleton script file generated with 'rails generate migration add_confirmable_to_users'):
我收到此错误:
要添加可确认 -
生成迁移:
编辑迁移:
http://guides.rubyonrails .org/migrations.html
https://github。 com/plataformatec/devise/wiki/操作方法:-升级到-Devise-2.0-migration-schema-style
I was getting this error:
To add Confirmable -
Generate the migration:
Edit the migration:
http://guides.rubyonrails.org/migrations.html
https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style
只要您只是删除相应字段已添加到架构中的选项(例如可确认的字段),您始终可以直接编辑用户模型,而无需进行新的迁移。
As long as you're just removing options where the appropriate fields were already added to your schema (like confirmable), you can always just edit the Users model directly without a new migration.
更改迁移文件中所需的行,然后按照以下说明重做迁移:
http://guides。 rubyonrails.org/migrations.html
Change the lines you want in the migration file, then redo the migration as per these instructions:
http://guides.rubyonrails.org/migrations.html