def create
      failures = []
      invites = InviteForm.new(invite_params).build_invites(current_user)
      ActiveRecord::Base.transaction do
        invites.each { |invite| invite.save ? do_invite(invite) : failures << invite.email }
      end

      respond_to do |format|
        format.html do
          if failures.empty?
            flash[:notice] = t('invitation.flash.invite_issued', count: invites.count)
          else
            flash[:error] = t('invitation.flash.invite_error', count: failures.count, email: failures.to_sentence)
          end
          redirect_to url_after_invite(invites.first) # FIXME: redirect to back
        end
        format.json do
          if failures.empty?
            # If we received a single email, json response should be a scalar, not an array.
            invites = params[:invite].key?('email') ? invites.first : invites
            render json: invites.as_json(except: [:token, :created_at, :updated_at]), status: 201
          else
            render json: {
              message: t('invitation.flash.invite_error', count: failures.count, email: failures.to_sentence),
              status: :unprocessable_entity
            }
          end
        end
      end
    end
def create
      failures = []
      invites = InviteForm.new(invite_params).build_invites(current_user)
      ActiveRecord::Base.transaction do
        invites.each { |invite| invite.save ? do_invite(invite) : failures << invite.email }
      end

      respond_to do |format|
        format.html do
          if failures.empty?
            flash[:notice] = t('invitation.flash.invite_issued', count: invites.count)
          else
            flash[:error] = t('invitation.flash.invite_error', count: failures.count, email: failures.to_sentence)
          end
          redirect_to url_after_invite(invites.first) # FIXME: redirect to back
        end
        format.json do
          if failures.empty?
            # If we received a single email, json response should be a scalar, not an array.
            invites = params[:invite].key?('email') ? invites.first : invites
            render json: invites.as_json(except: [:token, :created_at, :updated_at]), status: 201
          else
            render json: {
              message: t('invitation.flash.invite_error', count: failures.count, email: failures.to_sentence),
              status: :unprocessable_entity
            }
          end
        end
      end
    end
Create one or more Invite instances.
   invite: { invitable_id, invitable_type, email or emails:[] }