Skip to content
This repository
Browse code

Updating readme for ActionMailer::Base

  • Loading branch information...
commit 3762362eab9663b3c9bc6d4b831e402917f95e93 1 parent 311d99e
Mikel Lindsaar authored June 07, 2010

Showing 1 changed file with 32 additions and 1 deletion. Show diff stats Hide diff stats

  1. 33  actionmailer/lib/action_mailer/base.rb
33  actionmailer/lib/action_mailer/base.rb
@@ -36,6 +36,9 @@ module ActionMailer #:nodoc:
36 36
   # * <tt>attachments[]=</tt> - Allows you to add attachments to your email in an intuitive
37 37
   #   manner; <tt>attachments['filename.png'] = File.read('path/to/filename.png')</tt>
38 38
   #
  39
+  # * <tt>attachments.inline[]=</tt> - Allows you to add an inline attachment to your email
  40
+  #   in the same manner as <tt>attachments[]=</tt>
  41
+  #
39 42
   # * <tt>headers[]=</tt> - Allows you to specify any header field in your email such
40 43
   #   as <tt>headers['X-No-Spam'] = 'True'</tt>. Note, while most fields (like <tt>To:</tt>
41 44
   #   <tt>From:</tt> can only appear once in an email header, other fields like <tt>X-Anything</tt>
@@ -173,7 +176,7 @@ module ActionMailer #:nodoc:
173 176
   #
174 177
   #   class ApplicationMailer < ActionMailer::Base
175 178
   #     def welcome(recipient)
176  
-  #       attachments['free_book.pdf'] = { :data => File.read('path/to/file.pdf') }
  179
+  #       attachments['free_book.pdf'] = File.read('path/to/file.pdf')
177 180
   #       mail(:to => recipient, :subject => "New account information")
178 181
   #     end
179 182
   #   end
@@ -184,6 +187,34 @@ module ActionMailer #:nodoc:
184 187
   # and the second being a <tt>application/pdf</tt> with a Base64 encoded copy of the file.pdf book
185 188
   # with the filename +free_book.pdf+.
186 189
   #
  190
+  # = Inline Attachments
  191
+  # 
  192
+  # You can also specify that a file should be displayed inline with other HTML.  For example a 
  193
+  # corporate logo or a photo or the like.
  194
+  # 
  195
+  # To do this is simple, in the Mailer:
  196
+  # 
  197
+  #   class ApplicationMailer < ActionMailer::Base
  198
+  #     def welcome(recipient)
  199
+  #       attachments.inline['photo.png'] = File.read('path/to/photo.png')
  200
+  #       mail(:to => recipient, :subject => "Here is what we look like")
  201
+  #     end
  202
+  #   end
  203
+  # 
  204
+  # And then to reference the image in the view, you create a <tt>welcome.html.erb</tt> file and
  205
+  # make a call to +image_tag+ passing in the attachment you want to display and then call 
  206
+  # +url+ on the attachment to get the relative content id path for the image source:
  207
+  # 
  208
+  #   <h1>Please Don't Cringe</h1>
  209
+  # 
  210
+  #   <%= image_tag attachments['photo.png'].url -%>
  211
+  # 
  212
+  # As we are using ActionView's +image_tag+ method, you can pass in any other options you want:
  213
+  # 
  214
+  #   <h1>Please Don't Cringe</h1>
  215
+  # 
  216
+  #   <%= image_tag attachments['photo.png'].url, :alt => 'Our Photo', :class => 'photo' -%>
  217
+  # 
187 218
   # = Observing and Intercepting Mails
188 219
   #
189 220
   # Action Mailer provides hooks into the Mail observer and interceptor methods.  These allow you to

0 notes on commit 3762362

Please sign in to comment.
Something went wrong with that request. Please try again.