views:

1594

answers:

3

Hi there,

So Rails 2.2 added mailer layouts, which is great, except that I can't figure out how to make them work when I'm sending a multipart email..it's wrapping my mail content with the same layout for both the text/plain version and the text/html version. What I want is to wrap my layout around either only the text/html version, or to be able to have a separate layout for each.

Anybody encountered this? I haven't seen any mention of it elsewhere,

Cameron

A: 

+1

same problem no inf found - Itkin -

+2  A: 

See http://blog.kreeti.com/rails/multipart-emails-with-mailer-templates

maybe should put the monkey patch as an initializer?
ryw
+2  A: 

For future reference the solution in the blog post above amended in a second blog post is given below all credit to the above mentioned blog post. Solution blog post

Add this code to your environment.rb file to stop the mailer from applying layouts to plain text emails. It also has a check that will stop it from conflicting with the exception notification plugin.

# Do not use the mailer layout template for plain text emails
module ActionMailer
  class Base
    private    
    def candidate_for_layout?(options)
       (!options[:file] || !options[:file].respond_to?(:content_type) ||
          options[:file].content_type != 'text/plain') &&
          [email protected](:_exempt_from_layout?, default_template_name)
    end
  end
end
paulthenerd