Practical WordPress Development

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.


  1. Don

    This worked perfectly and was very timely. Thanks for taking the time to post this. I would recommend that you submit it to the Devise wiki.

    • Tom

      Good idea, Don. Will look into taking care of that!

  2. Andrew Bloom

    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 = ?",]

    • Tom

      Yes – nice suggestion! Updating the post to reflect this. Thanks!

  3. Richard Michael

    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).

    • Tom McFarlin

      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.

  4. Alex Popov

    For an up-to-date guide see this:

    How To: Add :confirmable to Users

Leave a Reply

© 2020 Tom McFarlin

Theme by Anders NorenUp ↑