Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Update README to show how to init draper for all ActionMailer methods. #141

merged 1 commit into from Mar 13, 2012


None yet
6 participants

joevandyk commented Mar 7, 2012

No description provided.


joevandyk commented Mar 7, 2012

Alternatively (and this is probably better), Draper could modify ActionMailer::Base and automatically add the proc to the defaults. I'll leave that as an exercise to the reader. :)


joevandyk commented Mar 8, 2012

Actually, I have a question about this. After ActionMailer sets the view context, what sets it back to the controller's context?

@steveklabnik steveklabnik added a commit that referenced this pull request Mar 13, 2012

@steveklabnik steveklabnik Merge pull request #141 from joevandyk/patch-1
Update README to show how to init draper for all ActionMailer methods.

@steveklabnik steveklabnik merged commit b50fb9c into drapergem:master Mar 13, 2012


steveklabnik commented Mar 13, 2012

Merging this for now, we can do the Right Thing later. :)

I am not sure about the answer to your question, actually.

deefour commented Apr 4, 2012

I think the line is supposed to be

default 'init-draper' => Proc.new { set_current_view_context }


defaults 'init-draper' => Proc.new { set_current_view_context }

steveklabnik commented Apr 4, 2012

You're right! Fixed.

deefour commented Apr 4, 2012

I haven't found the cause yet, but (for me at least) putting the set_current_view_context into a proc at class level causes the following error on 0.11.1 (tried git master repo too)

NoMethodError: undefined method `index' for #<#<Class:0x007fbb6b4f5bb8>:0x007fbb6b3a5790>
from /path/to/.rvm/gems/ruby-1.9.2-p290@my-gemset/gems/mail-2.4.4/lib/mail/encodings.rb:117:in `value_decode'

I'm not opening this as a separate ticket, as I'm not yet convinced I'm not simply missing something. Putting set_current_view_context directly into the mailer methods works as expected.


stevenharman commented Apr 25, 2012

@deefour I'm seeing the same thing on. Running on Rails 3.1

undefined method `index' for #<#<Class:0x007fc0918220e0>:0x007fc092d99fe0>
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/encodings.rb:117:in `value_decode'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/encodings.rb:101:in `decode_encode'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/fields/unstructured_field.rb:74:in `do_decode'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/fields/unstructured_field.rb:56:in `decoded'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/fields/unstructured_field.rb:107:in `wrapped_value'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/fields/unstructured_field.rb:70:in `do_encode'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/fields/unstructured_field.rb:52:in `encoded'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/field.rb:123:in `method_missing'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/header.rb:190:in `block in encoded'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/header.rb:189:in `each'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/header.rb:189:in `encoded'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/message.rb:1708:in `encoded'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionmailer-3.1.4/lib/action_mailer/base.rb:451:in `set_payload_for_mail'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionmailer-3.1.4/lib/action_mailer/base.rb:431:in `block in deliver_mail'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.1.4/lib/active_support/notifications.rb:53:in `block in instrument'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activesupport-3.1.4/lib/active_support/notifications.rb:53:in `instrument'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/actionmailer-3.1.4/lib/action_mailer/base.rb:430:in `deliver_mail'
/Users/steven/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/mail-2.3.3/lib/mail/message.rb:230:in `deliver'

Can someone else confirm that this does work? If so, we should open a new issue.


steveklabnik commented Apr 25, 2012

I'm talking with Rails Core about what to do in this case. Turns out the view context stuff is kinda complicated. See my comment here.

I'm getting this using Rails 3.1.4 and Draper 0.12.3 What it looks like is that ActionMailer is adding init-draper as a header with the proc as the value and dies when it tries to encode the proc, thinking it is a string.

Any ideas?


steveklabnik commented Jun 4, 2012

I'm not sure, Rails 3.1.x isn't really supported for anything but security fixes anymore (by Rails Core), so...

Fair enough.

FYI, that method of setting the view context struck me as a little weird. You're basically co-opting a method that's used to set default headers and using it to evaluate a block in the context of an instance of ActionMailer::Base.

As a quick fix in my app, I just overrode #mail and added this behavior

class ApplicationMailer < ActionMailer::Base
  def mail(*args, &block)
    # Draper requires that we set the current_view_context

steveklabnik commented Jun 4, 2012

Yeah, it is the current Right Way To Do It, but Rails is a bit awkward in this respect. Working on it.

Also running into @deefour's issue with undefined method 'index' on Rails 3.2.1. FWIW.

/cc @steveklabnik

Ended up working around the issue with @dlangevin's #mail override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment