Performance: Action Mailer setup
This affects page load speed indirectly by how email sending tasks are handled, impacting user interaction responsiveness and server resource usage.
class UserMailer < ApplicationMailer def welcome_email(user) mail(to: user.email, subject: 'Welcome!') end end # In controller UserMailer.welcome_email(@user).deliver_later
class UserMailer < ApplicationMailer def welcome_email(user) mail(to: user.email, subject: 'Welcome!') end end # In controller UserMailer.welcome_email(@user).deliver_now
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous email sending (deliver_now) | N/A | N/A | Blocks server response delaying paint | [X] Bad |
| Asynchronous email sending (deliver_later) | N/A | N/A | Non-blocking server response, faster paint | [OK] Good |
def name(params); ...; end with parentheses and semicolons optional but recommended for clarity.mail method requires keyword arguments with colons, e.g., to: user.email, and commas between arguments.class UserMailer < ApplicationMailer
def notify(user)
mail(to: user.email, subject: 'Notice')
end
end
UserMailer.notify(user).deliver_now?deliver_now method sends the email immediately when called on a mail object.notify method calls mail with valid parameters, so it returns a mail object ready to send.def alert(user) mail(to: user.email, subject: 'Alert') end
config/environments/production.rb is correct?enable_starttls_auto: true) for secure email sending.Pass the test and this pattern moves unknown