ruby-on-railsdevisedevise-confirmabledevise-invitable

how to avoid devise_invitable from sending a confirmation email?


from the docs i think it should to not send a confirmation email, but it is doing it.

Here's my setup for the invitable action:

class Users::InvitationsController < Devise::InvitationsController

def multiple_create
    if params[:multiple_emails].blank?
        build_resource
        render :new, notice: "something went wrong"
    else
        params[:multiple_emails].each do |email|
            User.invite!({email: email}, current_user) # current_user will be set as invited_by
        end
        if current_user.errors.empty?
            set_flash_message :notice, :send_instructions, :email => params[:multiple_emails]
            respond_with current_user, :location => after_invite_path_for(current_user)
        else
            respond_with_navigational(current_user) { render :new }
        end
    end
end
end

Solution

  • For the cases, where you have to use :confirmable for user registration and want to avoid sending confirmation letters with invitation:

    class User < ApplicationRecord
      after_create :skip_confirmation_notification!, unless: Proc.new { self.invitation_token.nil? }
    end