【问题标题】:Rails best practices of using layoutsRails 使用布局的最佳实践
【发布时间】:2014-09-18 14:40:58
【问题描述】:

我有两个派生自 ActionMailer 的类。但是它们的设计模板将是相同的。我将使用布局。我现在做的是

在提醒课中

Class Reminders < ActionMailer::Base
  layouts :mailer_template
end

在警报类中

Class Alerts < ActionMailer::Base
  layouts :mailer_template
end

在布局中我有 mailer_template.html

我的另一种方法是创建两个布局,称为reminders.html 和alerts.html,因为它们共享相同的代码,我可以有一个名为_mailer_template.html 的部分并在类中呈现这个部分。

现在在这里使用哪种最佳做法?

【问题讨论】:

    标签: ruby-on-rails layout actionmailer partials


    【解决方案1】:

    至于我:你不需要创建不必要的文件reminders.html, alerts.html, _shared_partial.html 只需使用layouts :layout_name。即使将来您需要单独的布局,您也可以这样做(但现在您不需要它)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      • 2012-10-30
      相关资源
      最近更新 更多