Generate an ActionMailer with preview, i18n, and spec file
Generates an ActionMailer for sending transactional emails, including:
/new-mailer User # Creates UserMailer
/new-mailer Order # Creates OrderMailer
/new-mailer Admin::Report # Creates Admin::ReportMailer
Read reference patterns. Load mailer patterns from:
skills/new-mailer/references/mailer-examples.mdpatterns/backend-patterns.mdstyles/backend-ruby.mdDetermine mailer name and actions. Parse the argument and infer:
UserMailer)Generate the mailer file. Create the mailer with:
frozen_string_literal: trueApplicationMailer inheritance@user and other instance variablesmail call with to: and subject:Generate email views. Create both HTML and text templates:
app/views/<mailer>/<action>.html.erbapp/views/<mailer>/<action>.text.erbGenerate mailer preview. Create preview class:
test/mailers/previews/<mailer>_preview.rb orspec/mailers/previews/<mailer>_preview.rbGenerate I18n translations. Add to locale files:
config/locales/mailers.en.ymlGenerate spec file. Create the spec with:
Run quality checks.
bundle exec rubocop -A app/mailers/<path>.rb spec/mailers/<path>_spec.rb
bundle exec rspec spec/mailers/<path>_spec.rb
Report results. Show generated files and preview URL.
app/mailers/<mailer_name>.rb
app/views/<mailer_name>/welcome.html.erb
app/views/<mailer_name>/welcome.text.erb
spec/mailers/<mailer_name>_spec.rb
spec/mailers/previews/<mailer_name>_preview.rb
config/locales/mailers.en.yml (appended)
For /new-mailer User:
Mailer: app/mailers/user_mailer.rb
# frozen_string_literal: true
# Sends transactional emails to users.
#
# @example Send welcome email
# UserMailer.welcome(@user).deliver_later
#
class UserMailer < ApplicationMailer
# Sends a welcome email to a newly registered user.
#
# @param user [User] the user to welcome
# @return [Mail::Message] the email message
def welcome(user)
@user = user
@login_url = new_session_url
mail(
to: @user.email,
subject: t('.subject', name: @user.name)
)
end
# Sends a password reset email.
#
# @param user [User] the user requesting reset
# @return [Mail::Message] the email message
def password_reset(user)
@user = user
@reset_url = edit_password_reset_url(@user.password_reset_token)
mail(
to: @user.email,
subject: t('.subject')
)
end
end
View: app/views/user_mailer/welcome.html.erb
Preview: spec/mailers/previews/user_mailer_preview.rb
# frozen_string_literal: true
# Preview user emails at http://localhost:3000/rails/mailers/user_mailer
class UserMailerPreview < ActionMailer::Preview
def welcome
UserMailer.welcome(User.first || FactoryBot.build(:user))
end
def password_reset
UserMailer.password_reset(User.first || FactoryBot.build(:user))
end
end
ApplicationMailerdeliver_later (not deliver_now) in application codeSearch for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer