Reputation: 2643
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>
Upvotes: 0
Views: 3227
Reputation: 2643
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.
Upvotes: 0
Reputation: 14282
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
Upvotes: 1