Challenge - 5 Problems
Mailer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this mailer method?
Given the following Rails mailer method, what will be the subject line of the sent email?
Ruby on Rails
class UserMailer < ApplicationMailer def welcome_email(user) @user = user mail(to: @user.email, subject: "Welcome to Our Site") end end # Assume user.email = 'test@example.com' # When UserMailer.welcome_email(user).deliver_now is called
Attempts:
2 left
💡 Hint
Look at the subject argument inside the mail method.
✗ Incorrect
The subject line is set explicitly in the mail method call as "Welcome to Our Site".
📝 Syntax
intermediate1:30remaining
Which option correctly defines a mailer template file name?
In Rails, which filename correctly matches the mailer method 'notification_email' in 'UserMailer' for an HTML email template?
Attempts:
2 left
💡 Hint
Rails expects template files to have the mailer method name and format with extension.
✗ Incorrect
Rails mailer templates for HTML emails use the pattern: mailer_name/method_name.html.erb.
🔧 Debug
advanced2:30remaining
Why does this mailer raise an error?
Examine this mailer method and identify the cause of the error when sending the email.
Ruby on Rails
class UserMailer < ApplicationMailer def alert_email(user) @user = user mail(to: user.email, subject: "Alert") do |format| format.html format.text end end end # Error: Missing template user_mailer/alert_email.html.erb
Attempts:
2 left
💡 Hint
Check the error message about missing template.
✗ Incorrect
Rails requires a matching template file for each format declared; missing alert_email.html.erb causes the error.
❓ state_output
advanced2:00remaining
What is the value of @greeting in this mailer template?
Given this mailer method and template, what will be the rendered value of @greeting in the email?
Ruby on Rails
class UserMailer < ApplicationMailer def custom_email(user) @greeting = "Hello, #{user.name}!" mail(to: user.email, subject: "Custom Greeting") end end # Template: app/views/user_mailer/custom_email.html.erb # <p><%= @greeting %></p> # Assume user.name = 'Alice'
Attempts:
2 left
💡 Hint
Instance variables set in the mailer method are available in the template.
✗ Incorrect
The @greeting variable is set with string interpolation using user.name, so it renders as "Hello, Alice!".
🧠 Conceptual
expert3:00remaining
Which option best describes how Rails mailers handle multipart emails?
How does Rails decide which email format (HTML or text) to send when a mailer defines both formats in its template?
Attempts:
2 left
💡 Hint
Think about how email clients handle different content types.
✗ Incorrect
Rails automatically creates a multipart email with both HTML and text parts if both templates exist, letting the client pick the best format.