Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

ruby on rails 3 - How do I enable :confirmable in Devise?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

see: Adding confirmable module to an existing site using Devise

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

You could also check the RailsCast on Devise:

http://railscasts.com/episodes/209-introducing-devise

Next it would be best to search for example applications on GitHub


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...