How do I preview emails in Rails?

Peter Nixey picture Peter Nixey · Aug 23, 2011 · Viewed 54.8k times · Source

This might be a dumb question but when I'm putting together an HTML email in Rails, is there a particularly easy built-in way to preview the template it in the browser or do I need to write some sort of custom controller that pulls it in as its view?

Answer

benjaminjosephw picture benjaminjosephw · Dec 18, 2013

Action Mailer now has a built in way of previewing emails in Rails 4.1. For example, check this out:

# located in test/mailers/previews/notifier_mailer_preview.rb

class NotifierPreview < ActionMailer::Preview
  # Accessible from http://localhost:3000/rails/mailers/notifier/welcome
  def welcome
    Notifier.welcome(User.first)
  end
end