bevanb
bevanb

Reputation: 8511

Accessing controller helpers in ActionMailer

I want to access a helper method in my email templates. The helper is defined in a controller, and is a :helper_method. How can I do that? I know how to use helper files in ActionMailer, but this is different.

edit

I don't want to pass the result of the helper into mailer method, since I'd have to do that on every single mail method.

Upvotes: 1

Views: 678

Answers (1)

emrahbasman
emrahbasman

Reputation: 2013

Just pass current_user to mailer method. Mailers shouldn't access session variables and your current_user method depends on a session variable. What if you send email as a background process? Who will be the current_user ?

MyMailer.hello_email(current_user).deliver 

class MyMailer < ActionMailer::Base 
  def hello_email(user)
    @user = user
  end
end

Upvotes: 2

Related Questions