在我的动作邮件中(rails 3.2.13)我有类似的东西
class RepaymentMailer < ActionMailer::Base
default from: "repayments@milaap.org"
def repayment_mail user, user_repayment_info, month_date
@mail_layout = if condition_true
'layout1'
else
'layout2'
end
mail(to: "#{user.first_name} <#{user.email}>",
from: "xxx@xxx.org",
bcc: ["xxx <xxx@xxx.org>"],
reply_to: 'xxx@xxx.org',
subject: "this is a test" ) do |format|
format.html { render layout: @mail_layout }
format.text
end
end
end
当我做
puts RepaymentMailer.repayment_mail(param1, param2, param3).deliver
即使repayment_mail模板存在,它也会给我错误
ActionView::MissingTemplate: Missing template repayment_mailer/repayment_mail with {:locale=>[:en], :formats=>[:text], :handlers=>[:erb, :builder, :coffee, :arb]}. Searched in:
如果我删除
do |format|
format.html { render layout: @mail_layout }
format.text
end
然后它可以正常工作。但显然我想要所需的布局。错误的原因可能是什么。