diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb index 1cb691e115..519407c3fc 100644 --- a/app/controllers/volunteers_controller.rb +++ b/app/controllers/volunteers_controller.rb @@ -32,22 +32,13 @@ def create authorize @volunteer if @volunteer.save - # invitation error handling - begin - @volunteer.invite!(current_user) - rescue => e - flash[:alert] = "Volunteer invitation failed. Reason: #{e.message}" - end - + @volunteer.invite!(current_user) # call short io api here - invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: @volunteer.raw_invitation_token, host: request.base_url) - - hash_of_short_urls = {0 => nil, 1 => nil} - if @volunteer.phone_number.present? - hash_of_short_urls = handle_short_url([invitation_url, request.base_url + "/users/edit"]) - end - - sms_status = deliver_sms_to @volunteer, account_activation_msg("volunteer", hash_of_short_urls) + raw_token = @volunteer.raw_invitation_token + invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: raw_token, host: request.base_url) + hash_of_short_urls = @volunteer.phone_number.blank? ? {0 => nil, 1 => nil} : handle_short_url([invitation_url, request.base_url + "/users/edit"]) + body_msg = account_activation_msg("volunteer", hash_of_short_urls) + sms_status = deliver_sms_to @volunteer, body_msg redirect_to edit_volunteer_path(@volunteer), notice: sms_acct_creation_notice("volunteer", sms_status) else render :new, status: :unprocessable_entity