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|
t.confirmable
end
add_index :users, :confirmation_token, :unique => true
end
def self.down
remove_column :users, :confirmable
end
end
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 = ?", Time.now]
You’ll be able to login with each existing user after that.


Leave a Reply
You must be logged in to post a comment.