Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding TextHelper to UserMailer

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!

like image 880
sscirrus Avatar asked Oct 25 '11 17:10

sscirrus


1 Answers

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
like image 135
dip00dip Avatar answered Oct 21 '22 16:10

dip00dip