LoginSignup
7
2

More than 3 years have passed since last update.

パスワードリセットのシステムテストをしていたら、Rails Missing host to link to! のエラーがおでましになった

Posted at

前提

・ruby 2.6.3
・Rails 6.0.3.1
・rspec-rails (3.9.1)

Rails Missing host to link to!

Rspecでパスワードリセットのsystem specを書いていたら

 ArgumentError:
            Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

上記のエラーが出ました。

ホストがないのでhostパラメータを指定するか、default_url_options [:host]を設定して!!

とのことでした。

確認URLを渡すメールが送れない状態みたいです。

自分は、default_url_options [:host]を設定することにしました。

config/environments/development.rb
config.action_mailer.default_url_options = { host: 'localhost:3000' }

開発環境には、設定してあるがテスト環境には確かに記述なし。

ので、テスト環境にも付け足す。

config/environments/test.rb
config.action_mailer.default_url_options = { host: 'localhost:3000' }

ちなみに、本番環境にデプロイしたも上記のようなエラーが出流みたいなので、本番環境にも付け足しとく。

config/environments/production.rb
config.action_mailer.default_url_options = { host: 'localhost:3000' }

上記設定で、エラー解消されました。

Missing host to link to! Please provide the :host parameter
RailsでMissing host to link to!が出たときに。model内でURL組み立てる場合の設定

7
2
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
7
2