Module: Invitation::UserRegistration

Extended by:
ActiveSupport::Concern
Defined in:
lib/invitation/user_registration.rb

Overview

UserRegistration should be included by your user registration controller.

Instance Method Summary collapse

Instance Method Details

#process_invite_token(new_user = nil) ⇒ Object

Check for an invitation token and process the invite. If an invitation is found, the user claims the invite.

Use this only when creating a new user. Invoke manually or from an after_action:

after_action :process_invite, only: [:create]

Invoke with new_user, or set an instance variable with the standard 'underscore' name of your user model class. For example, if your user model is UserProfile, this method will check for @user_profile.


29
30
31
32
33
# File 'lib/invitation/user_registration.rb', line 29

def process_invite_token(new_user = nil)
  new_user = user_instance_variable if new_user.nil?
  token = params[:invite_token]
  new_user.claim_invite token if !token.nil? && !new_user.nil?
end

#set_invite_tokenObject

Copy params to @invite_token. Your user registration form needs to include :invite_token, this method is the controller half of the glue.

Use this in your user registration controller in a before_action for the new action.

before_action :set_token, only: [:new]

15
16
17
# File 'lib/invitation/user_registration.rb', line 15

def set_invite_token
  @invite_token = params[:invite_token]
end