Unable to use helpers in ActionMailer #1898

Closed
mhuggins opened this Issue Jun 29, 2011 · 1 comment

1 participant

@mhuggins

According to this comment in ActionMailer::Base:

# You can even use Action Pack helpers in these views. For example:
#
# You got a new note!
# <%= truncate(@note.body, 25) %>

However, I am unable to use truncate in my mailer's view without generating an error.

ActionView::Template::Error: undefined method `truncate' for #<Mail::Body:0x102ab7ea0>
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/helpers/text_helper.rb:87:in `truncate'
from /Users/mhuggins/Sites/myapp/app/views/profile_mailer/new_message.html.erb:5:in `_app_views_profile_mailer_new_message_html_erb__509081069_2162793200'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/template.rb:143:in `send'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/template.rb:143:in `render'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/activesupport/lib/active_support/notifications.rb:57:in `instrument'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/template.rb:141:in `render'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/renderer/template_renderer.rb:40:in `render_template'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/activesupport/lib/active_support/notifications.rb:55:in `instrument'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/activesupport/lib/active_support/notifications.rb:55:in `instrument'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/renderer/abstract_renderer.rb:33:in `instrument'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/renderer/template_renderer.rb:39:in `render_template'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/renderer/template_renderer.rb:47:in `render_with_layout'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/renderer/template_renderer.rb:38:in `render_template'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/action_view/renderer/template_renderer.rb:12:in `render'
... 6 levels...
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/abstract_controller/rendering.rb:99:in `render'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:700:in `collect_responses_and_parts_order'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:711:in `each'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:711:in `each_template'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:696:in `collect_responses_and_parts_order'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:635:in `mail'
from /Users/mhuggins/Sites/myapp/app/mailers/profile_mailer.rb:14:in `new_message'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/abstract_controller/base.rb:167:in `send_action'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/abstract_controller/base.rb:167:in `process_action'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/abstract_controller/base.rb:121:in `process'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionpack/lib/abstract_controller/rendering.rb:45:in `process'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:456:in `process'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:451:in `initialize'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:438:in `new'
from /Users/mhuggins/.rvm/gems/ree-1.8.7-2011.03@myapp/bundler/gems/rails-4389fc973383/actionmailer/lib/action_mailer/base.rb:438:in `method_missing'
@mhuggins

Sorry for any confusion, marking this as invalid. I had an object named @message, but was accidentally trying to truncate message instead. Since message references the Mail::Message object to be delivered, it wasn't undeclared, but truncate() couldn't properly truncate the non-String object.

@mhuggins mhuggins closed this Jul 1, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment