Help us understand the problem. What is going on with this article?

[Rails] Mailerを作ってみた

(1) 叩いて3点セット作成

$ rails g mailer SendPasswordMailer
create  app/mailers/send_password_mailer.rb
invoke  erb
create    app/views/send_password_mailer
invoke  rspec
create    spec/mailers/send_password_mailer_spec.rb
create    spec/mailers/previews/send_password_mailer_preview.rb

- mailer
- erb(ディレクトリ)
- rspec(なければtestファイル)

(2) Mailer書く

class SendPasswordMailer < ApplicationMailer
  def send_password(name, password)
    @name = name
    @password = password
    @service_domain = ENV["SERVICE_DOMAIN"]

    mail to: 'sample@co.jp',
         subject: "【株式会社YAMADA】パスワードを送付しました。"
  end
end

(3) 対応するerbを作る

def send_passwordのように対応するファイル名をつける。

send_password.html.erb

(4) 呼び出す

SendPasswordMailer.send_password(name, password).deliver_now

もっと楽したいなあ

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away