1

In my requirement ,there are different domain names for single project.I would like to send reset password link with a domain name where the user requested for the reset password.For that I have done the follows 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 have used sidekiq for delayed mailer and updated like follows on entire application

Notifier.delay.password_reset(user.id)

As the mailer was configured with sidekiq it was using default domain name provided in configuration only and it was not using the dynamic domain name provided from request on application_controller.rb

Any suggestion to get the dynamic domain on mailers running by sidekiq would be greatly appreciated.

Rails - 3.2.8 Ruby - 1.9.3 sidekiq - 2.13.1

Thanks!!!

kanna
  • 366
  • 2
  • 19

2 Answers2

1

One of the options would be to associate each user with a domain and use this information when sending the email in sidekiq.

Rafal
  • 2,576
  • 2
  • 18
  • 13
  • 1
    Agreed. Either store the domain with the user, or pass it as an argument when you call your password_reset method, I don't think sidekiq jobs retrain any other information from the controller action that initiated them (I normally use Dealyed::Job so I might be wrong on that). – Paul Leader Jul 05 '14 at 02:08
  • FYI,Actually in my case the user is not restricted to single domain and can use any domain at any time.From which domain request was placed,that domain should come on link of email. – kanna Jul 05 '14 at 09:15
  • You could always add a User#last_host_name to the user table and when they login to your site, update the information with the current host. – Rafal Jul 05 '14 at 23:55
  • Thanks,I appreciate your idea. – kanna Jul 07 '14 at 09:09
0

You'll need to construct the url yourself rather than rely on AM to do it for you.

Mike Perham
  • 21,300
  • 6
  • 59
  • 61