Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top