aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-06-07 23:25:49 -0400
committerMikel Lindsaar <raasdnil@gmail.com>2010-06-07 23:25:49 -0400
commit80a044edb663e6bc619b0755e30f9db10e37e9e8 (patch)
tree6f01897a9c85e79ce3ff83fa8c22230e9e7196f8 /railties/guides
parent3762362eab9663b3c9bc6d4b831e402917f95e93 (diff)
downloadrails-80a044edb663e6bc619b0755e30f9db10e37e9e8.tar.gz
rails-80a044edb663e6bc619b0755e30f9db10e37e9e8.tar.bz2
rails-80a044edb663e6bc619b0755e30f9db10e37e9e8.zip
Updating ActionMailer basics guide to have inline attachments
Diffstat (limited to 'railties/guides')
-rw-r--r--railties/guides/source/3_0_release_notes.textile1
-rw-r--r--railties/guides/source/action_mailer_basics.textile31
2 files changed, 32 insertions, 0 deletions
diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index 75c03be87c..35a386613f 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -565,6 +565,7 @@ Action Mailer has been given a new API with TMail being replaced out with the ne
* All mailers are now in <tt>app/mailers</tt> by default.
* Can now send email using new API with three methods: +attachments+, +headers+ and +mail+.
+* ActionMailer now has native support for inline attachments using the <tt>attachments.inline</tt> method.
* Action Mailer emailing methods now return <tt>Mail::Message</tt> objects, which can then be sent the +deliver+ message to send itself.
* All delivery methods are now abstracted out to the Mail gem.
* The mail delivery method can accept a hash of all valid mail header fields with their value pair.
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index a2a748c749..8eb48e2751 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -211,6 +211,37 @@ attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
NOTE: If you specify an encoding, Mail will assume that your content is already encoded and not try to Base64 encode it.
+h5. Making Inline Attachments
+
+Inline attachments are now possible in ActionMailer. While previously in the pre 3.0 version of Rails, you could do inline attachments, it involved a lot of hacking and determination to pull it off.
+
+ActionMailer now makes inline attachments as trivial as they should be.
+
+* Firstly, to tell Mail to turn an attachment into an inline attachment, you just call <tt>#inline</tt> on the attachments method within your Mailer:
+
+<ruby>
+def welcome
+ attachments.inline['image.jpg'] = File.read('/path/to/image.jpg')
+end
+</ruby>
+
+* Then in your view, you can just reference <tt>attachments[]</tt> as a hash and specify which attachment you want to show, calling +url+ on it and then passing the result into the <tt>image_tag</tt> method:
+
+<erb>
+<p>Hello there, this is our image</p>
+
+<%= image_tag attachments['image.jpg'].url %>
+</erb>
+
+* As this is a standard call to +image_tag+ you can pass in an options hash after the attachment url as you could for any other image:
+
+<erb>
+<p>Hello there, this is our image</p>
+
+<%= image_tag attachments['image.jpg'].url, :alt => 'My Photo',
+ :class => 'photos' %>
+</erb>
+
h4. Mailer Views
Mailer views are located in the +app/views/name_of_mailer_class+ directory. The specific mailer view is known to the class because it's name is the same as the mailer method. So for example, in our example from above, our mailer view for the +welcome_email+ method will be in +app/views/user_mailer/welcome_email.html.erb+ for the HTML version and +welcome_email.text.erb+ for the plain text version.