Rails的文件上传http和https协议



  def default_url_options(options={})
    if Rails.env.production?
      options.merge(protocol: :https)
    else
      options
    end
  end


In Rails 5.1.4, I have tested the following scenarios:

# 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
阅读量: 562
发布于:
修改于: