如何在 Devise 中启用 :confirmable? [英] How do I enable :confirmable in Devise?
问题描述
Devise 的最新版本默认没有启用 :confirmable.我已经将相应的列添加到用户模型中,但找不到任何关于如何启用 :confirmable 的代码示例.
The newest version of Devise doesn't have :confirmable enabled by default. I already added the respective columns to the User model but cannot find any code examples of how to enable :confirmable.
在哪里可以找到好的示例或启用它需要什么代码?
Where can I find a good example or what code do I need to enable it?
推荐答案
要启用"可确认,您只需要将其添加到您的模型中,例如:
to "enable" confirmable, you just need to add it to your model, e.g.:
class User
# ...
devise :confirmable , ....
# ...
end
之后,您必须创建并运行迁移,将所需的列添加到您的模型中:
after that, you'll have to create and run a migration which adds the required columns to your model:
# rails g migration add_confirmable_to_devise
class AddConfirmableToDevise < ActiveRecord::Migration
def self.up
add_column :users, :confirmation_token, :string
add_column :users, :confirmed_at, :datetime
add_column :users, :confirmation_sent_at , :datetime
add_column :users, :unconfirmed_email, :string
add_index :users, :confirmation_token, :unique => true
end
def self.down
remove_index :users, :confirmation_token
remove_column :users, :unconfirmed_email
remove_column :users, :confirmation_sent_at
remove_column :users, :confirmed_at
remove_column :users, :confirmation_token
end
end
我建议检查源代码以了解 Confirmable 的工作原理:
I'd recommend to check the source code to see how Confirmable works:
https://github.com/plataformatec/devise/blob/master/lib/devise/models/confirmable.rb
您还可以在 Devise 上查看 RailsCast:
You could also check the RailsCast on Devise:
http://railscasts.com/episodes/209-introducing-devise
接下来最好在 GitHub 上搜索示例应用程序
Next it would be best to search for example applications on GitHub
这篇关于如何在 Devise 中启用 :confirmable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!