LoginSignup
3
5

More than 3 years have passed since last update.

Railsのdevise導入でdefault_url_optionsの設定でハマった

Posted at

deviseのユーザー認証設定

デフォルトの場合以下のようにconfig.action_mailer.default_url_options{ host: 'localhost', port: 3000 }と設定されると多います。

development.rb
  # default url
  config.action_mailer.default_url_options = {  host: 'localhost', port: 3000 }
  # mail setting
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :user_name => Rails.application.credentials.gmail[:user_name],
    :password => Rails.application.credentials.gmail[:password],
    :authentication => :plain,
    :enable_starttls_auto => true
  }

その場合認証メールで送られてくるURLはhttp://localhost:3000/users/confirmation?confirmation_token=-XiHyA_1xCxhk846ae9G
みたいな形になる思います。

Dockerでrootディレクトリが3000ポートを付けない形で構築したのでポート番号がない形でURLを作成しなければいけないので以下のように設定を変更しました。

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

URLが変更されない

本来であればhttp://localhost/users/confirmation?confirmation_token=-XiHyA_1xCxhk846ae9Gのような形でURLが生成されるはずがされず数時間ハマりました。

結論

Dockerの再起動で反映された。

Web開発をしていると常にハマるポイントがありますが、再起動で動くことが多々あるので「ハマったら再起動してみる」ということをもっと心がけて行きたいです。

3
5
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
3
5