AuthHelpers is a collection of modules and controllers to extend your Authlogic models. Currently it supports Confirmable and Recoverable behavior.
Switch branches/tags
Nothing to show
Pull request Compare This branch is 17 commits ahead of dcrec1:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


License: MIT
Version: 0.4.1

You can also read this README in pretty html at the GitHub project Wiki page:


AuthHelpers is a collection of modules to improve your Authlogic models. It
mainly exposes some convenience methods to help on confirmation and passwords
management, it also deals automatically with associations and notifications.

Authlogic also include some controllers to deal with the modules added. For
example, if you add Recoverable to your model, you can have all password
management for free, if you inherit from the Recoverable controller:

  class AccountPasswordsController < AuthHelpers::Controller::Recoverable

This functionality is powered by InheritedResources, which is available at:

You can see an example at:


Install AuthHelpers is very easy. It is stored in GitHub, so just run the

   gem sources -a
   sudo gem install josevalim-auth_helpers

If you want it as plugin, just do:

   script/plugin install git://

Example app


  class Account < ActiveRecord::Base
    acts_as_authentic do |a|
      a.validations_scope = :accountable_type
      a.require_password_confirmation = false

    include AuthHelpers::Model::Confirmable
    include AuthHelpers::Model::Recoverable
    include AuthHelpers::Model::Updatable

== Confirmable

Adds the confirmation handling. It sends an e-mail to the user on account
creation, and adds find_and_confirm, find_and_resend_confirmation_instructions
as class methods plus confirmed? and confirm! as instance methods.

When used with Updatable, also sends an e-mail the user changes his e-mail address.

== Recoverable

Adds the reset password code handling. Adds find_and_resend_confirmation_instructions
and find_and_reset_password class methods plus reset_password instance method.

== Updatable

It adds email and password confirmations and hack into update_attributes to
ensure the another confirmation instruction is sent when the user changes the

Authlogic already supports password confirmation, but it's coupled with the
validates_length_of :password_confirmation, which is unecessary. So in order
to use this module, is advisable to disable require_password_confirmation from

  acts_as_authentic do |a|
    a.require_password_confirmation = false


All modules come with specs, that's why the library does not have tests per se.
So if you want to test the Account model declared above, just do:

  describe Account do
    include AuthHelpers::Spec::Confirmable
    include AuthHelpers::Spec::Recoverable
    include AuthHelpers::Spec::Updatable

    before(:each) do
      @valid_attributes = {
        :email                 => "",
        :email_confirmation    => "",
        :password              => "abcdef",
        :password_confirmation => "abcdef"

    it "should create a new instance given valid attributes" do

The only requirement you have for the tests is to have a @valid_attributes
instance variable set with a hash of valid attributes.


AuthHelpers also comes with default notification files. At some point you will
want to prettify your notification views, so you just need to do:

  AuthHelpers::Notifier.sender = %("José Valim" <>)
  AuthHelpers::Notifier.template_root = "#{RAILS_ROOT}/app/views"

Then make a copy of the plugin views folder to your app/views and start to work
on them.

Notification has some basic specs which fail if you don't include the perishable
token in your emails. Just put a file in spec/models/auth_helpers/notifier.rb
with the following contents:

  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

  module AuthHelpers
    describe Notifier do
      include AuthHelpers::Spec::Notifier

== Asynchronous notifications

Notification e-mails are by default delivered synchronously by ActionMailer, but in most cases the delay caused by direct processing is just a drawback. Instead an e-mail can be sent into a delivery job queue for delayed processing, and the user won't even notice except for a bit faster signup response - WIN-WIN. AuthHelpers don't have this built in because same pattern might be useful in your other project notifiers (and therefore could imply code duplication), so therefore you should use this excellent generic ActionMailer asynchronous delivery extension: (enhanced version of the brain behind:

This triggers ActionMailer to always put all type of e-mail deliveries as database backed delayed jobs (i.e. will not be lost upon server issues) - handled by DelayedJob ( All you need to do (except of install the gem/plugin and it's dependencies - straight forward):

  # config/initializers/action_mailer.rb
  ActionMailer::Base.class_eval do
    include Delayed::Mailer

..and you got asynchronous mail delivery.


Those helpers rely on I18n. Assuming the account model below, you need to
configure the following messages:

          already_confirmed: was already confirmed
          not_found: could not be found. Are you sure you gave the right e-mail address?
            invalid_confirmation: is invalid. Are you sure you copied the right link from your e-mail?
            invalid_reset_password: is invalid. Are you sure you copied the right link from your e-mail?

Need more?

Right now, this plugin contains the modules that I needed so far. If you are
building an invitation system on top of your authlogic models, you could fork
the project and add the Invitable module. Uou will never have to write it again
in your next projects and it shouldn't be harder than inheriting a few modules
and few controllers.

Bugs and Feedback

If you discover any bugs, please send an e-mail to

Copyright (c) 2009 José Valim