【问题标题】:Rails Model Variables in MailerMailer 中的 Rails 模型变量
【发布时间】:2016-03-23 08:46:40
【问题描述】:

我不是百分百确定我能解释我希望做什么,但这里有一个尝试:

我有几个模型需要为其构建邮件。这是一个:

 class SendLink < ApplicationMailer
  default :from => 'info@mysite.com'


def email(order)
    @order = order
     mail(
  :subject => 'Critical Documentation Needed' ,
  :to  => @order.recipient ,
  :track_opens => 'true'
)
  end
 end

除了上面显示的order 模型之外,我还有其他几个需要邮件的模型,它们的内容几乎完全相同。因此,理想情况下,我想为每个模型反复重用邮件程序和模板,并让模型成为变量。

是否有可能使模型成为邮件程序中的变量,如果可以,将使用哪种语法?

【问题讨论】:

    标签: ruby-on-rails actionmailer mailer mvcmailer


    【解决方案1】:

    根据您的解释,您可以为所有相似的模型重复使用相同的邮件。

    class SendLink < ApplicationMailer
      default :from => 'info@mysite.com'
    
      def email( object )
        @object = object
        mail(
          :subject => 'Critical Documentation Needed' ,
          :to  => @object.recipient ,
          :track_opens => 'true'
        )
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2017-08-22
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多