I have read so many different ways to set default_url_options. But at least in Rails 5.1.4, only some of them worked. The thing is, often one works for console but not for controller, or the opposite happens:

# in development.rb
config.action_controller.default_url_options({:protocol => 'https'})
config.action_controller.default_url_options(:protocol => 'https')
# Does not work

# in development.rb, outside config block
Rails.application.routes.default_url_options[:protocol] = 'https'
# Does not work, but works under console

# in routes.rb
Rails.application.routes.draw do
  default_url_options protocol: :https
# Does not work, but works under console

# in ApplicationController
def default_url_options(options={})
  { secure: true }
end
# Does not work

# in ApplicationController
def default_url_options
  { protocol: :https }
end
# Works in browser, but does not work under console

# in development.rb
config.action_controller.default_url_options= {:protocol => 'https'}
# Works in browser, but does not work under console

This means we probably want to set the options at two different places for it to work always. I think this caused many stackoverflow questions, and deserve to have a Rails repo issue.