如何启用:在Devise中可以确认? [英] How do I enable :confirmable in Devise?
问题描述
最新版本的Devise没有:默认情况下启用了confirmable。我已经将相应的列添加到User模型中,但找不到如何启用的任何代码示例: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?
推荐答案
要启用可确认,您只需要将其添加到您的模型中,例如: p>
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
请参阅:
添加确认模块到现有的网站使用Devise
我建议检查源代码,看看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-introduction-devise
接下来,最好在GitHub上搜索示例应用程序
Next it would be best to search for example applications on GitHub
这篇关于如何启用:在Devise中可以确认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!