Rails 7.1 Supports Multiple Preview Paths For Mailers.

ActionMailer previews provide a way to see how our emails look in the browser by visiting a special URL that renders them without actually sending the emails.

It is particularly useful for testing and developing email templates.

class UserInvitationPreview < ActionMailer::Preview
  def send_invitation_email
    UserInvitationMailer.with(invitation: Invitation.last).invitation_email
  end
end

Before

By default, Rails looks for mailer previews in the test/mailers/previews directory.

If we want to customize the location of our mailer previews, we can only specify a single path using the preview_path configuration, as ActionMailer is limited to one preview path.

For example, if we want to add lib/mailer_previews to it, we can configure it as

config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"

This works well for small to medium apps, but it can become difficult in larger apps where mailer previews need to be organized across multiple directories.

After

Rails 7.1 supports multiple preview paths for mailers with config.action_mailer.preview_paths

config.action_mailer.preview_paths << "#{Rails.root}/lib/mailer_previews"
config.action_mailer.preview_path = [
  "#{Rails.root}/lib/mailer_previews",
  "#{Rails.root}/app/mailers/previews",
  "#{Rails.root}/engines/admin/app/mailers/previews"
]

Note: With Rails 7.1 config.action_mailer.preview_path has been deprecated.

Need help on your Ruby on Rails or React project?

Join Our Newsletter