1
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?

More than 3 years have passed since last update.

【Rails】Cloud9で送信メールのプレビュー時の自分のホスト名と指定のURLの指定方法【Railsチュートリアル11章】

Posted at

自分がつまづいた時の状況

Railsチュートリアル第11章アカウントの有効化でHTMLメールとテキストメールのプレビューをする際に、アプリケーションのdevelopment環境の設定ファイルの設定と、Railsサーバー起動時のURLが分からず、送信メールのプレビューが表示できませんでした。

・クラウドIDE:AWS Cloud9
・Rails:v6.0.3
・OS:Win

config/environments/development.rb
Rails.application.configure do
  .
  .
  .
  config.action_mailer.raise_delivery_errors = false

  host = 'example.com' # ここの指定方法が分からなかった(自分のホスト名を指定する)
  config.action_mailer.default_url_options = { host: host, protocol: 'https' }
  .
  .
  .
end

自分のホスト名の調べ方

まず、自分のホスト名を調べる方法ですが、 Cloud9のPreview PreviewRunning Applicationを押下し、アドレスバーがついているpreviewタブを表示させます。 その後、そのアドレスバーに表示されているlocalhost以下の文字列が自分のアドレスになります。

その自分のホスト名の中でもhttpsから.vsfの間の文字列を先ほどのdevelop環境の設定ファイルに反映します。

image.png

config/environments/development.rb
config.action_mailer.raise_delivery_errors = false
  
  host = 'hoge.vfs.cloud9.us-east-2.amazonaws.com'     # クラウドIDE
  config.action_mailer.default_url_options = { host: host, protocol: 'https' }

設定ファイルを変更したら、Railsサーバーは再起動してください。

送信メールのプレビューのURL

URLですが、下記でプレビューが表示されました。 ホストの後ろに「/rails/mailers/user_mailer」とつけるだけでした。
https://hogehoge.vfs.cloud9.ap-northeast-1.amazonaws.com/rails/mailers/user_mailer

image.png

参考

Railsチュートリアル第11章アカウントの有効化 rails tutorial にて 送信メールのプレビューができない rails チュートリアルの11章の2・2にてクラウドIDEのホスト名がわからない
1
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
1
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?