问题
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!!!
回答1:
One of the options would be to associate each user with a domain and use this information when sending the email in sidekiq.
回答2:
You'll need to construct the url yourself rather than rely on AM to do it for you.
来源:https://stackoverflow.com/questions/24577202/dynamic-domain-name-in-rails-action-mailer-while-using-sidekiq