[Ruby] I was addicted to setting default_url_options with devise introduction of Rails

less than 1 minute read

devise user authentication settings

In the default case, it is often set as { host:'localhost', port: 3000 } in config.action_mailer.default_url_options as shown below.

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
  }

In that case, the URL sent by the authentication email is http://localhost:3000/users/confirmation?confirmation_token=-XiHyA_1xCxhk846ae9G. I think it will look like this.

Since the root directory was built in Docker without 3000 ports, I had to create a URL without a port number, so I changed the settings as follows.

development.rb


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

URL does not change

Originally, the URL was not supposed to be generated in the form of http://localhost/users/confirmation?confirmation_token=-XiHyA_1xCxhk846ae9G and I was addicted for a few hours.

Conclusion

It was reflected by restarting Docker.

There are always points that I am addicted to when doing web development, but since it often works by restarting, I would like to keep in mind that “I will restart when I am addicted”.