5
2

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 5 years have passed since last update.

Production環境でdeviseのパスワードリセットメールを送るとlocalhostのリンクになってしまう

Posted at

初投稿になります。
deviseでForgot your password?からメール送信する機能についてハマったので、端的ですが残します。

起こったこと

・ローカル(development)環境 =>ドメインのついたURLが送信される
https://ドメイン/users/password/edit?reset_password_token=トークン
・プロダクション環境=>localhostがついたURLが送信される
https://localhost:3000/users/password/edit?reset_password_token=トークン

production.rb
  # メール送信用
  config.action_mailer.default_url_options = { host: "abc.def(ドメイン)" }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.smtp_settings = {
    :address => 'email-smtp.us-west-2.amazonaws.com(SESのエンドポイント)',
    port: 587,
    authetication: :login,
    user_name: Rails.application.secrets.smtp_user_name,
    domain: "abc.def(ドメイン)",
    password: Rails.application.secrets.smtp_user_password,
    :enable_starttls_auto => true
  }
secrets.yml
production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  aws_access_key_id: <%= ENV["AWS_ACCESS_KEY_ID"] %>
  aws_secret_access_key: <%= ENV["AWS_SECRET_ACCESS_KEY"] %>
  smtp_user_name: <%= ENV["SMTP_USER_NAME"] %>
  smtp_user_password: <%= ENV["SMTP_USER_PASSWORD"] %>

回避できたこと

config>initializers>devise.rb
config.scoped_views = true
5
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?