Where do I put helper methods for ActionMailer views?

前端 未结 6 1257
无人共我
无人共我 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:47

    An already answered question, but I didn't get where/what-file to modify from the other SO responses. Here is how I did it:

    At the bottom of app/config/initializers/devise.rb you can add this:

    Devise::Mailer.class_eval do
      helper :application # includes "ApplicationHelper"
    end
    

    This example will include the methods in /app/helpers/application_helper.rb. You could include another helper-file instead - if, for example, the method is only for the mailer or used for one other controller only. The def I needed is used all over, so I put in in that file so all views could access it.

提交回复
热议问题