我在哪里将辅助方法用于ActionMailer视图? [英] Where do I put helper methods for ActionMailer views?

查看:71
本文介绍了我在哪里将辅助方法用于ActionMailer视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法,该方法需要一个字符串数组并将其连接起来,以便它们执行以下操作:

I have a method that takes an array of strings and joins them so they do something like this:

>> my_arr
=> ["A", "B", "C"]
>> and_join(my_arr)
=> "A, B, and C"

我希望我的邮件访问者可以访问,所以我可以将一些信息输出到电子邮件中。我似乎找不到放置它并将其放置在application_helper.rb文件中的好地方,并且找不到该文件。

Which I'd like my mailer to have access to so I can output some information into an email. I can't seem to find a good place to put it and putting it in the application_helper.rb file and it doesn't find it there. Where should it go?

推荐答案

使用邮件中的 helper 方法来定义要使用的帮助程序类

Use the helper method in your mailer to define the helper class to use

# mailer_helper.rb
module MailerHelper
  def and_join(arr)
    # whatever …
  end
end

# my_mailer.rb
class MyMailer < ActionMailer::Base
  helper MailerHelper
  …
end

然后您也可以在视图中使用这些方法。

then you can use the methods in views as well.

这篇关于我在哪里将辅助方法用于ActionMailer视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆