Access helpers from mailer?

前端 未结 11 1830
夕颜
夕颜 2020-12-05 17:25

I have trying to access helper methods from a rails 3 mailer in order to access the current user for the session.

I put the helper :application in my mailer class,

11条回答
  •  感动是毒
    2020-12-05 17:32

    If you want to call helper method from ActionMailer you need to include helper (module) in Mailer file as, if Helper module name is “UserHelper”, then need to write following in Mailer file

    class CommentMailer < ActionMailer::Base
        default :from => "Andre Fournier "
        add_template_helper(UserHelper)
    end
    

    Or

    class CommentMailer < ActionMailer::Base
        default :from => "Andre Fournier "
        include UserHelper
    end
    

    Hope this is helpful.

提交回复
热议问题