Render :inline in ActionMailer

Hello everyone,

while attempting to figure out how to render an inline template as body
of a
mail message in an ActionMailer I am somewhat lost and hope that
somebody on
the list can point me into the right direction.

My current code looks like this (with minor deletions to improve

– 8< –
class RegistrationMailer < ActionMailer::Base
def confirmation(registration)
recipients “#{registration.full_name} <#{}>”
from “<#{registration.event.organizer_alias_email}>”

tmpl = registration.event.registration_confirmation_template
subject tmpl.subject

part "text/plain" do |p|
  p.body render :inline => tmpl.body, :registration => registration

– 8< –

Unfortunately, calling render throws an exception about a nil object:

| You have a nil object when you didn’t expect it!
| You might have expected an instance of Array.
| The error occurred while evaluating nil.each

– 8< –
_evaluate_assigns_and_ivars' /var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/renderable.rb:31:insend’
render' /var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/base.rb:301:inwith_template’
render' /var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/base.rb:264:inrender’
render' /raid/home/tg/workspace/MHNVeranstaltungen/app/models/registration_mailer.rb:30:inconfirmation’
part' /raid/home/tg/workspace/MHNVeranstaltungen/app/models/registration_mailer.rb:28:inconfirmation’
– 8< –

Line 310 maps to the “elsif” branch in base.rb, so most likely
controller.request.template_format is nil:

| def template_format
| if defined? @template_format
| @template_format
| elsif controller && controller.respond_to?(:request)
| @template_format = controller.request.template_format.to_sym
| else
| @template_format = :html
| end
| end

But, what would be the right way to set it?

I know that my approach somewhat violates the MVC pattern. An
would probably be to call render from within the corresponding view.