0

I would like to use I18n in a Rails utility module which is in my lib directory. The utility method gets invoked in a mailer.

The module is defined like

module MyUtils
  def self.build_collection_full_email(collection)
    I18n.t('app_name') + " <" + self.build_collection_email(collection) + ">"
  end
end

The mailer has a call like this:

sender_name = MyUtils.build_collection_full_email(@collection)

However, when this gets run in the context of the mailer, I get an error

NoMethodError: undefined method `I18n' for Rails:Module

It seems like I need to include a dependency so that the utility method knows how find the I18n module, but I haven't been able to find this in the documentation for I18n.

Will
  • 2,768
  • 1
  • 17
  • 15

1 Answers1

0

do require 'i18n' in this file