Ruby - devise : confirmations_controller stop registrations_controller

26 Views Asked by At

I have a problem with devise I can't find the solution.

When a user sign_up, I need to call several services to make his profile. So here is the registrations_controller.rb.

require_relative '../../../app/services/affinities'
require_relative '../../../app/services/astroprofil'
require_relative '../../../app/services/geocode'

class Users::RegistrationsController < Devise::RegistrationsController
  ASTROPROFIL = Astroprofil.new
  AFFINITIES = Affinities.new
  GEOCODE = Geocode.new

  after_action :create_astroprofil, only: %i[new create]
  after_action :create_affinities, only: %i[new create]

  private

  def create_astroprofil
    return unless user_signed_in?

    ASTROPROFIL.profil(current_user)
  end

  def create_affinities
    return unless user_signed_in?

    affinities(current_user, ten_mates)
  end

  def affinities(user, mates)
    AFFINITIES.partner_report(user, mates)
    AFFINITIES.sign_report(user, mates)
    AFFINITIES.match_percentage(user, mates)
  end

  def ten_mates
    mates_by_gender = User.where(gender: current_user.looking_for).where.not(id: current_user.id)
    return mates_by_gender.sample(10)
  end
end

When I sign up everything works perfectly, a new user is entirely created.

But as soon as I try to add a confirmation per mail with devise, the mails are sent but it stops the 'create_astroprofil' and the 'create_affinities' methods.

Do you have any idea about what's happening ?

1

There are 1 best solutions below

2
brcebn On

I would say it's coming from this line

registrations_controller.rb#L28

Since you cannot login without having confirmed your email, I'm pretty sure create_astroprofil and create_affinities are called but their first line is return unless user_signed_in?.

2 options here:

  • Astroprofil.new and Affinities.new can be called for an unconfirmed user
  • Called create_astroprofil and create_affinities from ConfirmationController#show