draper: Decorator is unable to access helper methods after sending an ActionMailer email.
When a helper method is called inside a decorator after sending an email, it throws an error stating that the helper method is not defined.
>> UserMailer.send_email.deliver
>> User.new.decorate.h.current_user
NoMethodError: undefined method `current_user' for #<#<Class:0x00000004c34ef8>:0x00000004c43570>
from ...gems/draper-1.4.0/lib/draper/helper_proxy.rb:29:in `block in define_proxy'
from (irb):3
from ...gems/railties-4.2.0/lib/rails/commands/console.rb:110:in `start'
I tried debugging this to no avail. Draper does not seem to have any association with ActionMailer.
I have created a sample app which reproduces this error: https://github.com/notalex/draper-mailer-error
Any help would be appreciated.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 5
- Comments: 18
calling Draper::ViewContext.clear! right after actionmailer is called fixed this for me. This caused me a lot of headache. Suggesting to put it in the Readme 😃
@codebycliff The bug is still present in the latest version 4.0.2.
Yeah, I’m still experiencing this problem as well. @notalex Do you mind reopening this, if possible?
Might be worth tagging @codebycliff, you seem like you are one of the more recently active contributors that could reopen this.
@notalex You could access by this way:
+1, I checked the code and it seems like each time any mailer calls
view_contextmethod, Draper switches it’s global view_context to that mailer’s one, which is kind of surprising behaviour.