require "securerandom"

module UniqueToken

  def generate_token_for(attribute)
    loop do
      token = SecureRandom.urlsafe_base64(15)
      if self.class.where(attribute => token).count > 0
        next
      else
        self.send(:"#{attribute}=", token)
        break token
      end
    end
  end

end

require "securerandom"

module UniqueToken

  def generate_token_for(attribute)
    loop do
      token = SecureRandom.urlsafe_base64(15)
      token += 'b'
      if self.class.where(attribute => token).count > 0
        next
      else
        self.send(:"#{attribute}=", token)
        break token
      end
    end
  end

end

Append frab 'b' to the confirmation token, since base64 padding confuses URL recognition in email clients.
Append frab 'b' to the confirmation token, since base64 padding confuses
URL recognition in email clients.
