Using Devise Invitable

Aug 28th, 2013

I love using Devise for application authentication. When I was creating the Realtime QA Tool I needed to make sure that the sign up form wasn’t publicly accessible. So I started doing a little bit of searching I found Devise Invitable. Devise invitable allows you to invite users via e-mail to your application.

Getting up and running with Devise Invitable is really easy. The documentation is pretty good and walks you through the setup process step by step.

You start out with two simple commands

1
2
rails generate devise_invitable:install
rails generate devise_invitable MODEL

Then, update your devise model to include the :invitable module

1
2
3
class User < ActiveRecord::Base
  devise :database_authenticatable, :confirmable, :invitable
end

and you’re good to go.

After Devise Invitable is installed and ready to go, I usually end up making an invitation action in one of my controllers. Devise Invitable does allow you to make a dedicated controller for it. But I find I can usually accomplish everything with a simple action that looks something like that

1
2
3
4
def invite_user
  @user = User.invite!(:email => params[:user][:email], :name => params[:user][:name])
  render :json => @user
end

Just like that, you can now invite users to your application.

Comments