Challenge - 5 Problems
Email Preview Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
How does Rails email preview render the email?
In Rails, when you open an email preview in the browser, what does Rails do to show the email content?
Attempts:
2 left
💡 Hint
Think about how you can see the full email content without sending it.
✗ Incorrect
Rails email previews call the mailer method and render the email body directly in the browser. This lets you see the email as it would appear to the user without actually sending it.
📝 Syntax
intermediate2:00remaining
Correct syntax to define a preview class for UserMailer
Which of the following is the correct way to define a preview class for a mailer named UserMailer in Rails?
Attempts:
2 left
💡 Hint
Preview classes inherit from a special Rails class for previews.
✗ Incorrect
Preview classes must inherit from ActionMailer::Preview to work correctly in Rails.
❓ state_output
advanced2:00remaining
What is the output of this preview method?
Given this preview method in Rails, what will be the subject line shown in the preview if User.first has email 'test@example.com'?
class UserMailerPreview < ActionMailer::Preview
def notify
UserMailer.notify(User.first)
end
end
And the mailer method:
class UserMailer < ApplicationMailer
def notify(user)
mail(to: user.email, subject: "Hello, #{user.email}")
end
end
Attempts:
2 left
💡 Hint
Look at how the subject is built using the user email.
✗ Incorrect
The subject line uses string interpolation to include the user's email, so it will show "Hello, test@example.com".
🔧 Debug
advanced2:00remaining
Why does this email preview raise an error?
This preview method raises an error when accessed:
class UserMailerPreview < ActionMailer::Preview
def alert
UserMailer.alert(nil)
end
end
Mailer method:
class UserMailer < ApplicationMailer
def alert(user)
mail(to: user.email, subject: "Alert")
end
end
What is the cause of the error?
Attempts:
2 left
💡 Hint
Check what happens when you call a method on nil.
✗ Incorrect
Passing nil as user causes user.email to raise a NoMethodError because nil has no email method.
🧠 Conceptual
expert2:00remaining
Why use email previews in Rails development?
Which of the following best explains the main benefit of using email previews in Rails development?
Attempts:
2 left
💡 Hint
Think about how previews help before sending emails.
✗ Incorrect
Email previews allow developers to view and verify email content quickly in the browser without sending real emails, making design and testing faster and safer.