ActionMailer fails with "undefined function" when called from delayed job
So if I try sending an email开发者_C百科 with action mailer directly, I can use all application helpers like url_for, content_for etc, but when I try to do the exact same action [sending email] with delayed_job [send_later] I getting a delayed job fail, of undefined function content_for etc, so it is like no helpers are loaded in my ActionMailer. I am using rails 2.3.8, active_mailer 2.3.8 and delayed_job 2.0.3
Thanks!!
Your problem is that your sw is not a child of ActionView since your sw is not being initiated as a result of a web request. Rather, your sw is being initiated by the DelayedJob machinery.
Solution: create and use your own instance of ActionView --
action_view = ActionView::Base.new # used for calling helper tags, eg link_to
html = action_view.link_to(link_text, url)
# etc...
精彩评论