如何在我的 ActionMailer 视图中使用我的视图助手? [英] How to use my view helpers in my ActionMailer views?
问题描述
我想在我的 ReportMailer 视图 (app/views/report_mailer/usage_report.text.html.erb
) 中使用我在 app/helpers/annotations_helper.rb
中定义的方法>).我该怎么做?
I want to use the methods I defined in app/helpers/annotations_helper.rb
in my ReportMailer views (app/views/report_mailer/usage_report.text.html.erb
). How do I do this?
基于本指南,看起来add_template_helper(helper_module)
方法可能会做什么我想要,但我不知道如何使用它.
Based on this guide it seems like the add_template_helper(helper_module)
method might do what I want, but I can't figure out how to use it.
(顺便说一句,您是否有理由在邮件程序视图中访问一组不同的帮助程序?这很烦人.)
(BTW, is there a reason you get access to a different set of helpers in mailer views? This is pretty annoying.)
推荐答案
在您用来管理电子邮件的邮件程序类中:
In the mailer class that you are using to manage your emails:
class ReportMailer < ActionMailer::Base
add_template_helper(AnnotationsHelper)
...
end
这篇关于如何在我的 ActionMailer 视图中使用我的视图助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!