module Invitation::Invitable
Any model you wish to invite users to join should extend this concern. This is typically an organization or resource with limited membership like an “account” or “project”.
Your code is responsible for managing associations between your Invitable
and your user model.
For example, to make the model class Account an organization that can receive an invitation
class Account < ActiveRecord::Base invitable named_by: :name has_many :account_memberships has_many :users, through: :account_memberships end
Public Instance Methods
invitable(options = {})
click to toggle source
All resources or organizations should be invitable.
@param [Hash] options - either named_by: <method name> or named: <String>
# File lib/invitation/invitable.rb, line 22 def invitable(options = {}) has_many :invites, as: :invitable class_attribute :invitable_options self.invitable_options = {} case when options[:named_by] then invitable_options[:named_by] = options[:named_by] when options[:named] then invitable_options[:named] = options[:named] else raise 'invitable requires options be set, either :name or :named_by. \ e.g.: `invitable named: "string"` or `invitable named_by: :method_name`' end include Invitation::Invitable::InstanceMethods end