Home>

Chapter 11 of the rails tutorial (implementation of authentication email sending function) link contents , I deployed to heroku, tried to sign up in the production environment and send an authentication email, but failed with the following error message.
] (ee871a047f17829ec61df090bd68e59b.png)
All tests pass in the development environment and the settings should be as per the tutorial, but I have no idea where the problem is.
How can I resolve it?

development.rb
Rails.application.configure do
  # Settings specified here will take precedence over those in config/application.rb.
  # In the development environment your application's code is reloaded on
  # every request.This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false
  # Do not eager load code on boot.
  config.eager_load = false
  # Show full error reports.
  config.consider_all_requests_local = true
  # Enable/disable caching. By default caching is disabled.
  if Rails.root.join ('tmp/caching-dev.txt'). exist?
    config.action_controller.perform_caching = true
    config.cache_store =: memory_store
    config.public_file_server.headers = {
      'Cache-Control' =>"public, max-age = # {2.days.seconds.to_i}"
    }
  else
    config.action_controller.perform_caching = false
    config.cache_store =: null_store
  end
  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method =: test
  host = 'https://evening-ridge-47211.herokuapp.com/' # Copying here will fail. Please adapt to your environment.
  config.action_mailer.default_url_options = {host: host}
  ActionMailer :: Base.smtp_settings = {
    : address =>'smtp.sendgrid.net',
    : port =>'587',
    : authentication =>: plain,
    : user_name =>ENV ['SENDGRID_USERNAME'],
    : password =>ENV ['SENDGRID_PASSWORD'],
    : domain =>'heroku.com',
    : enable_starttls_auto =>true
  }
  config.action_mailer.perform_caching = false
  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation =: log
  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error =: page_load
  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true
  # Suppress logger output for asset requests.
  config.assets.quiet = true
  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
  # Use an evented file watcher to asynchronously detect changes in source code,
  # routes, locales, etc. This feature depends on the listen gem.
  config.file_watcher = ActiveSupport :: EventedFileUpdateChecker
end
Heroku logs
2019-11-20T12: 20: 08.744164 + 00: 00 app [web.1]: I, [2019-11-20T12: 20: 08.744091 # 4] INFO-: [f52d78bb-0df1- 44a6-b935-ea15e8c0c161] Completed 500 Internal Server Error in 194ms (ActiveRecord: 12.6ms)
2019-11-20T12: 20: 08.745390 + 00: 00 app [web.1]: F, [2019-11-20T12: 20: 08.745314 # 4] FATAL-: [f52d78bb-0df1-44a6-b935-ea15e8c0c161]
2019-11-20T12: 20: 08.745542 + 00: 00 app [web.1]: F, [2019-11-20T12: 20: 08.745460 # 4] FATAL-: [f52d78bb-0df1-44a6-b935-ea15e8c0c161] ActionView :: Template :: Error (Missing host to link to! Please provide the: host parameter, set default_url_options [: host], or set: only_path to true):

I reset the heroku database and recreated the side, but the results were the same.

Supplemental information (FW/tool version etc.)

AWS Cloud9
Heroku

  • Answer # 1

    It was solved by setting host URL in production.rb instead of

    development.rb.

Related articles