【问题标题】:How can I set the value of 'config.action_mailer.default_url_options' with domain.name?如何使用 domain.name 设置 'config.action_mailer.default_url_options' 的值?
【发布时间】:2012-07-14 03:33:57
【问题描述】:

我必须为我的设备使用进行设置。
但我的应用程序允许用户通过 2 个域进行访问。
我想用用户访问的域设置 'config.action_mailer.default_url_options = { :host =>'。

我该怎么做?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 configuration actionmailer


    【解决方案1】:

    如果您想要实现的是您发送的电子邮件中的 URL 是使用当前主机或域构建的,那么 default_url_options 方法将不起作用,因为它只在应用程序启动时设置一次 - 请求对象不可用在那种情况下 AFAIK,但仅限于控制器操作。

    您可以尝试在 mailer 类中的电子邮件中生成 URL,而不使用默认主机,如下所示(未测试):

    class Mailer < ActionMailer::Base
    
      def welcome(user, host)
        @url = url_for(host: host, controller: ..., action: ...) 
        # construct rest of email here 
      end
    
    end
    

    然后使用请求中的适当主机从您的控制器调用它:

    Mailer.welcome(current_user, request.host).deliver
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      相关资源
      最近更新 更多