Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A nod to James on this, as it helped me get our mailer working right.</p> <p>A slight refinement to this: First, we use the block arguments within the blocks to add parts (I had problems when I didn't). </p> <p>Also, if you want to use layouts, you have to use #render directly. Here's an example of both principles at work. As shown above, you need to make sure you keep the html part last.</p> <pre><code> def message_with_attachment_and_layout( options ) from options[:from] recipients options[:to] subject options[:subject] content_type "multipart/mixed" part :content_type =&gt; 'multipart/alternative' do |copy| copy.part :content_type =&gt; 'text/plain' do |plain| plain.body = render( :file =&gt; "#{options[:render]}.text.plain", :layout =&gt; 'email', :body =&gt; options ) end copy.part :content_type =&gt; 'text/html' do |html| html.body = render( :file =&gt; "#{options[:render]}.text.html", :layout =&gt; 'email', :body =&gt; options ) end end attachment :content_type =&gt; "application/pdf", :filename =&gt; options[:attachment][:filename], :body =&gt; File.read( options[:attachment][:path] + '.pdf' ) end </code></pre> <p>This example uses an options hash to create a generic multipart message with both attachments and layout, which you would use like this:</p> <pre><code>TestMailer.deliver_message_with_attachment_and_layout( :from =&gt; 'a@fubar.com', :to =&gt; 'b@fubar.com', :subject =&gt; 'test', :render =&gt; 'test', :attachment =&gt; { :filename =&gt; 'A Nice PDF', :path =&gt; 'path/to/some/nice/pdf' } ) </code></pre> <p>(We don't actually do this: it's nicer to have each mailer fill in a lot of these details for you, but I thought it would make it easier to understand the code.)</p> <p>Hope that helps. Best of luck.</p> <p>Regards, Dan</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload