Forum: Ruby on Rails Layout on Email

Posted by Rawlins (Guest)
on 2010-07-16 16:02
(Received via mailing list)
Hello Guys,

Very new to Rails an enjoying myself a great deal. Been playing around
with the ActionMailer today sending emails. I'm currently sending a
multipart email using the naming conventions for my views to send both
an HTML and a TEXT version of the content.

contact.text.html.erb
contact.text.plain.erb

and this is working just perfectly. What I'm now looking to do is
apply a layout to the HTML emails that are sent from the system, so
that all have a uniform look and feel.

I understand how I can apply a layout to a standard HTML view which
gets rendered in the browser but I'm struggling to figure out how this
can be done, if at all, for HTML emails.

I'd appreciate any help you can offer, if you need any more
information then please let me know.

Thanks,

Robert
Posted by Rawlins (Guest)
on 2010-07-17 14:19
(Received via mailing list)
Hello All,

I've been looking into this a little more this morning and found this
in the docs 
http://guides.rubyonrails.org/action_mailer_basics...

This suggests that I should be able to create a layout file with a
certain naming convention that should be picked up when the mail is
rendered.

My mailer class i defined like this: http://pastebin.com/BQ0n6Fm4

I've then created the layout /layouts/
notifications_mailer.text.html.erb

However, when sending the mails the layout is still not picked up. I'm
not receiving any error messages either.

I appreciate any further input people can offer.

Thanks,

Robert
Posted by Bill Walton (Guest)
on 2010-07-17 14:28
(Received via mailing list)
Hi Robert,

On Sat, Jul 17, 2010 at 7:18 AM, Rawlins <robert@supporttime.com> wrote:
>
> I've then created the layout /layouts/
> notifications_mailer.text.html.erb
>
> However, when sending the mails the layout is still not picked up. I'm
> not receiving any error messages either.

Have you tried explicitly specifying the layout in your mailer class?

layout 'notifications'

Best regards,
Bill
Posted by Rawlins (Guest)
on 2010-07-19 11:43
(Received via mailing list)
Hello Bill,

I've now solved the issue, although still confused.

I followed your advice of adding the explicite statement but simply
got an error saying that /layouts/notifications.erb was no present.

I then removed the explicite statement and changes the name of my
layout (contradictory to the docs) from:

/layouts/notifications_mailer.text.html.erb

to

/layouts/notifications.text.html.erb

and it all sprung into life and appears to be working just fine! go
figure! :-s My only guess is that the docs is based on the assumption
that my mailer class is called NotificationsMailer and not just
Notifications?

Either way the docs confused me a little, however, with your help I'm
now up and running.

Thanks,

Robert
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.