Where do I put helper methods for ActionMailer views?

前端 未结 6 1270
无人共我
无人共我 2020-12-09 16:41

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(m         


        
6条回答
  •  半阙折子戏
    2020-12-09 16:54

    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.

提交回复
热议问题