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
readability):

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

tmpl = registration.event.registration_confirmation_template
subject tmpl.subject

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

end
end
– 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< –
/var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/base.rb:310:in
_evaluate_assigns_and_ivars' /var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/renderable.rb:31:insend’
/var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/renderable.rb:31:in
render' /var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/base.rb:301:inwith_template’
/var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/renderable.rb:30:in
render' /var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_view/base.rb:264:inrender’
/var/lib/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:567:in
render' /raid/home/tg/workspace/MHNVeranstaltungen/app/models/registration_mailer.rb:30:inconfirmation’
/var/lib/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/part_container.rb:28:in
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
alternative
would probably be to call render from within the corresponding view.

Thanks,
Thilo