You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2021. It is now read-only.
TylerRick edited this page Aug 16, 2012
·
10 revisions
If you find yourself needing to introduce confirmable to your user model after the application has already been used for sometime, you will end up marking existing users as unconfirmed in the application.
For example, assume that you have a system full of users and you need to implement email notifications for user accounts. In doing this, existing user accounts will be left unconfirmed thus unable to log in.
Here's how you can introduce confirmable to users while also marking existing users as confirmed.
First, make sure that you've created a migration to add the proper columns:
classAddConfirmableToUsers < ActiveRecord::Migration# Note: You can't use change, as User.update_all with fail in the down migrationdefupadd_column:users,:confirmation_token,:stringadd_column:users,:confirmed_at,:datetimeadd_column:users,:confirmation_sent_at,:datetime# add_column :users, :unconfirmed_email, :string # Only if using reconfirmableadd_index:users,:confirmation_token,:unique=>true# User.reset_column_information # Need for some types of updates, but not for update_all.# To avoid a short time window between running the migration and updating all existing# users as confirmed, do the followingUser.update_all(:confirmed_at=>Time.now)# All existing user accounts should be able to log in after this.enddefdownremove_column:users,:confirmation_token,:confirmed_at,:confirmation_sent_at# remove_column :users, :unconfirmed_email # Only if using reconfirmableendend
Next, add :registerable and :confirmable to the User model:
devise:registerable,:confirmable
If not using reconfirmable, update the configuration in config/intializers/devise.rb