Class: InvitationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/invitations_controller.rb

Overview

Creates invitations for users to join organizations (works with new and pre-existing users)

Instance Method Summary collapse

Instance Method Details

#createObject

POST /create



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/invitations_controller.rb', line 18

def create
  self.invitation = Invitation.new(invitation_params)
  authorize invitation

  user_invitation_service.call(invitation) do |err_msg|
    self.title = "Inviting a user to join #{current_organization.title}"
    logger.warn "Unable to create Invitation: #{err_msg}"
    flash.now[:error] = err_msg
    render :new
    return :unable_to_create_invitation # avoid leaking nil
  end

  logger.info "Created #{invitation} for #{invitation.recipient_email} to #{invitation.organization}"
  redirect_to organization_url(current_organization), notice: "Invitation sent to #{invitation.recipient_email}"
end

#newObject

GET /organizations/1/invitations/new



11
12
13
14
15
# File 'app/controllers/invitations_controller.rb', line 11

def new
  self.title = "Invite a user to join #{current_organization.title}"
  self.invitation = Invitation.new
  authorize invitation
end