Dynamic domain name in Rails mailer when using sidekiq

In my requirement there are different domain names for one project. I would like to send a reset password link with the domain name where the user requested a reset password. For this, I did the following in application_controller.rb and it works well.

before_filter :set_mailer_host def set_mailer_host ActionMailer::Base.default_url_options[:host] = request.host_with_port $url_host = request.host_with_port end 

Later, I used sidekiq for a deferred mail program and updated as it should throughout the application

 Notifier.delay.password_reset(user.id) 

Since the mailer was configured using sidekiq, it used the default domain name specified only in the configuration, and it did not use the dynamic domain name provided from the request for application_controller.rb

Any suggestion to get a dynamic domain in email programs run by sidekiq would be greatly appreciated.

Rails - 3.2.8 Ruby - 1.9.3 sidekiq - 2.13.1

Thanks!!!

+1
source share
2 answers

One option is to associate each user with a domain and use this information when sending email to sidekiq.

+1
source

You will need to create the URL yourself, rather than relying on AM to do this for you.

0
source

Source: https://habr.com/ru/post/1213286/


All Articles