How do I enable :confirmable in Devise?

前端 未结 6 2248
我在风中等你
我在风中等你 2020-12-04 19:58

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

6条回答
  •  误落风尘
    2020-12-04 20:04

    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

提交回复
热议问题