16

This question is related to: How to use my view helpers in my ActionMailer views?

I have a UserMailer.rb and I am trying to add TextHelper so I can use pluralize(@x, "x"). I've tried a few things but none seem to work:

class UserMailer < ActionMailer::Base
  1. helper :text
  2. add_template_helper(TextHelper)

3. application.rb
  config.to_prepare do
    ActionMailer::Base.helper "text"
  end

Do you know how I can get pluralize to work in my e-mails? Thanks!

Community
  • 1
  • 1
sscirrus
  • 55,407
  • 41
  • 135
  • 228

1 Answers1

27

That's how it worked for me:

class UserMailer < ActionMailer::Base
  include ActionView::Helpers::TextHelper

  def notify(alarms)
    mail(:subject => "#{alarms.size} new #{pluralize(alarms.size, 'alarm')}", ...
  end
end
dip00dip
  • 441
  • 4
  • 4