Dynamic domain name in Rails action mailer while using sidekiq

最后都变了- 提交于 2019-12-13 00:43:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!