2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Railsチュートリアルのメールプレビューを見やすくした(gem letter_opener_web)

Last updated at Posted at 2024-03-31

こんにちは!学びと成長しくみデザイン研究所の斉藤です。
Railsチュートリアルの第14章が終わった段階のリポジトリをベースにして、letter_opener_web を導入します。
letter_opener_web を導入することで、使い勝手の悪いデフォルトのメールプレビュー画面が改善できます。

プレビュー画面(Before => After)

Before

1

After

2

  • メリット
    • URLが http://localhost:3000/letter_opener でシンプルでわかりやすい
    • 複数のメールプレビューを確認できる

導入手順

gem追加

Gemfile
group :development do
  gem 'letter_opener_web', '2.0.0' # <= 追加
  gem "web-console",         "4.2.0"
  gem "solargraph",          "0.50.0"
  gem "irb",                 "1.10.0"
  gem "repl_type_completor", "0.1.2"
end

config/routes.rb にmount

routes.rb
Rails.application.routes.draw do
  mount LetterOpenerWeb::Engine, at: '/letter_opener' if Rails.env.development?

# 〜 以下省略 〜

config/environments/development.rb に設定追加

development.rb
# 以下3行はすでに記載されている設定
host = 'localhost:3000'
config.action_mailer.default_url_options = { host:, protocol: 'http' }
config.action_mailer.perform_caching = false

config.action_mailer.delivery_method = :letter_opener_web # <= 追加
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?