aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-06-08 21:23:29 +0200
committerXavier Noria <fxn@hashref.com>2010-06-08 21:23:29 +0200
commit751f79a03351f1f0d21436b2b947352b97ded093 (patch)
tree9dd053597389241398c9173ab7f565697bef055f /railties/guides
parente7e6ee3e7b075f5447697a6038cb46d65f9b137a (diff)
parentab2877cbe89e266ee986fc12e603abd93ac017ad (diff)
downloadrails-751f79a03351f1f0d21436b2b947352b97ded093.tar.gz
rails-751f79a03351f1f0d21436b2b947352b97ded093.tar.bz2
rails-751f79a03351f1f0d21436b2b947352b97ded093.zip
Merge remote branch 'rails/master'
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 44ada7f5a4..41ea5d5822 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.