views:

21

answers:

1

Like it is in many newsletter services, I want to use Ruby on Rails to write a Newsletter. Now I want to provide a link in this email to view this newsletter in a browser, if the email is not shown correctly in Email Client. How can I do this?

+1  A: 

I'm not sure if you're asking how to include a link in e-mail, or how to display the newsletter on your site. I'll try to give some basic advice on each.

E-mail views use erb by default, just like page views on your site. Therefore, you add dynamic content the same way. If your e-mail goes out in HTML format:

<%= link_to 'View Online', newsletter_url(@newsletter) %>

If it goes out in plaintext format:

<%= newsletter_url(@newsletter) %>

Even in plaintext format, URLs and e-mail addresses are made clickable by most e-mail clients.

Of course, this means your newsletter should be stored in the database like any other model, with a controller and views. Use the "show" action for displaying the newsletter to viewers.

Jaime Bellmyer
Thanks for your quick response, my problem is how to display the email on my site. So I didn't have any idea on how to do this. But thanks to your advise, I will now try to create a controller which renders the mail templates for the Browser.
jigfox