From 80a044edb663e6bc619b0755e30f9db10e37e9e8 Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Mon, 7 Jun 2010 23:25:49 -0400 Subject: Updating ActionMailer basics guide to have inline attachments --- railties/guides/source/3_0_release_notes.textile | 1 + .../guides/source/action_mailer_basics.textile | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'railties/guides/source') 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 app/mailers 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 attachments.inline method. * Action Mailer emailing methods now return Mail::Message 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 #inline on the attachments method within your Mailer: + + +def welcome + attachments.inline['image.jpg'] = File.read('/path/to/image.jpg') +end + + +* Then in your view, you can just reference attachments[] as a hash and specify which attachment you want to show, calling +url+ on it and then passing the result into the image_tag method: + + +

Hello there, this is our image

+ +<%= image_tag attachments['image.jpg'].url %> +
+ +* 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: + + +

Hello there, this is our image

+ +<%= image_tag attachments['image.jpg'].url, :alt => 'My Photo', + :class => 'photos' %> +
+ 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. -- cgit v1.2.3