如何在 ActionMailers 之间共享方法
我有两个邮件程序:(
class Mailer1 < ActionMailer::Base
def mail
if check_something?
end
end
private
def check_something?
end
end
class Mailer2 < ActionMailer::Base
def another_mail
if check_something?
end
end
private
def check_something?
end
end
我知道我可以为实际的邮件模板引入视图帮助程序,但是我如何才能使其适用于控制器类型的“帮助程序”方法 - 因为如今 ActionMailers 是从抽象控制器派生的。)
那么,在哪里可以我声明 check_something? ,如何才能让我的两个邮件程序都可以访问它?
I have two mailers:
class Mailer1 < ActionMailer::Base
def mail
if check_something?
end
end
private
def check_something?
end
end
class Mailer2 < ActionMailer::Base
def another_mail
if check_something?
end
end
private
def check_something?
end
end
(I understand I can pull in view helpers for the actual mail templates, but how can I make it work for controller-type "helper" methods - as ActionMailers derive from Abstract Controller these days.)
So, where can I declare check_something?, and how can I make it accessible to both my mailers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需创建一个基类,就像您的 http 控制器默认使用 ApplicationController 一样:
Just create a base class, like you get by default with ApplicationController for your http controllers: