CodeNewbie Community 🌱

Mike Rogers
Mike Rogers

Posted on

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 http://127.0.0.1:3000/rails/mailers 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
    UserMailer.user_welcome_notification(user)
  end

  private

  def user
    @user ||= FactoryBot.build(:user)
  end
end
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.

Oldest comments (5)

Collapse
 
damion_towne profile image
Damion Towne

Cybersecurity for schools is becoming increasingly important as technology continues to play a significant role in education. Schools store and handle sensitive data such as student records, financial information, and confidential correspondence that must be protected from cyber attacks. If you want best cybersecurity services for schools in california then this cybersecurity for schools california will be very handy option for you. Schools also face a range of cybersecurity threats, including phishing, malware attacks, and ransomware. These attacks can compromise the privacy and safety of students and staff, disrupt learning, and damage the reputation of the school.

Collapse
 
jobytavish profile image
Aliciya12

Some crystals are believed to have protective properties, helping to shield the body and energy field from negative influences. Try master healer for best results. Black tourmaline, for example, is often used for protection against electromagnetic radiation, while amethyst is said to provide spiritual protection and dispel negative energy.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.