Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 818
Colin Wu Avatar asked Jan 17 '18 17:01

Colin Wu


1 Answers

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
like image 133
Colin Wu Avatar answered Nov 15 '22 08:11

Colin Wu