Adding :confirmable To Users in Devise

Update 2/16/2012: I’ve posted this to an article on the Devise wiki. It’s likely that the article will continue to be updated by the community on GitHub. If this article appears out of date, refer to the wiki.

One of the challenges of working with Devise is that you may end up introducing functionality into the authentication layer long after initial requirements have been built.

I recently needed to add email notifications for user account creation. That worked fine, but all of the existing user accounts were left unconfirmed.

Make sure that you’ve created a migration to add the proper columns:

class AddConfirmableToUsers < ActiveRecord::Migration
  def self.up
    change_table(:users) do |t|
    add_index :users, :confirmation_token, :unique => true

  def self.down
    remove_column :users, :confirmable

And added the :registerable and :confirmable accessors to the User model:

devise :registerable, :confirmable

To confirm existing user accounts, load up a Rails console (production, if that’s where you’re running it):

rails console production

Iterate through each user setting their confirmed_at attribute equal to the current time and save the user:

User.update_all ["confirmed_at = ?",]

You’ll be able to login with each existing user after that.

7 Replies to “Adding :confirmable To Users in Devise”

  1. Thanks for the migration. Small tip, it is much quicker to do the following instead of iterating over each User and running the full validations.

    User.update_all ["confirmed_at = ?",]

  2. You could put the `User.update_all` into the migration itself, and avoid the manual production step (and possibly forgetting to do it when you deploy).

    1. True – and this is a good point! Depending on the nature of the project, it may be easier for some rather than others to do this. In my case, I was able to easily handle it as I was the primary developer on this particular project and only needed to do it once.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.