Tuesday, 7 February 2012

Adding 'confirmable' to Devise

I found myself needing to add 'confirmable' to Devise today, and I wish I'd installed it in the first place. For this you need the following migration:

class AddConfirmableToUsers < ActiveRecord::Migration
  def change
    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
Initially I missed out the 'unconfirmed_email' column, but it transpired I needed it - I'm not entirely sure why because I've yet to see any emails go into there, even unconfirmed ones. Not including it produced errors. And of course you need to add ':confirmable' to the list of modules specified in your user.rb model. Mine looks like this:
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable,

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!