Colin Wu
Colin Wu

Reputation: 699

Rails 4: How to use ApplicationHelper methods in mailer view

I have a helper defined in my application_helper.rb that I would like to use in my mailer view, but just doing

<%= helper_method(param) %>

in the mailer_view.html.erb file gets me an 'undefined method' error.

Is there another way to do this? I would hate to have to put the same helper somewhere else.

Thanks.

Upvotes: 5

Views: 2463

Answers (1)

Colin Wu
Colin Wu

Reputation: 699

Apparently this has been asked before (who knew!) :). The answer is to include

helper ApplicationHelper

in the example_mailer.rb file:

class ExampleMailer < ApplicationMailer
  helper ApplicationHelper
  ...
end

Upvotes: 10

Related Questions