DEV Community

Mike Rogers ✈️
Mike Rogers ✈️

Posted on • Originally published at

Review Emails with ActionMailer::Preview

Rails is one of my favourite frameworks, I think because it ships with a little known feature called ActionMailer::Preview, which I really want every Rails developer to know about :D

It renders your mailers & lets your preview them in the browser, which means if you want to tweak some code or totally redesign it, you can just visit on your local development machine & get building.

Code Sample

# spec/mailers/previews/user_mailer_preview.rb
# Preview all emails at http://localhost:3000/rails/mailers
class UserMailerPreview < ActionMailer::Preview

  def user_welcome_notification


  def user
    @user ||=
Enter fullscreen mode Exit fullscreen mode

FactoryBot For Sample Data

I used to use User.first as the starting point for my sample data, but I think a better approach is to use the FactoryBot factories. The main advantage is it encourages me to write better factories & increases the value for money they offer.

Latest comments (0)