0

I have a html.erb file used for an email template. Is there any way to include a helper module and use it's methods within this file? Something like:

a mails_helper.rb file:

module MailsHelper
  def mail_to
    "foo"
  end
end

and in mail_template.html.erb:

<% include MailsHelper %>
  <h2> This mail was sent to: <%= mail_to %> </h2>
naomi
  • 2,583
  • 2
  • 22
  • 39

2 Answers2

1

Add helper :mail to the top of your ActionMailer derived class
ex:- app/mailers/mails_mailer.rb

class MailMailer < ActionMailer::Base
  helper :mails

  ...
end

Checkout this answer

Community
  • 1
  • 1
Tony Vincent
  • 13,354
  • 7
  • 49
  • 68
0

Name the helper file with same prefix as the ActionMailer's file name.

For example: mailer: users_mailer.rb helper: users_mailer_helper.rb

According to the ruby on rails naming conventions - any view rendered by UsersMailer would have access to your helper methods.

naomi
  • 2,583
  • 2
  • 22
  • 39