0

有没有办法可以设置一个基本协议来使用

render :action => "myaction"
redirect_to :action => "myaction"

而不是打电话

render :action => "myaction", :protocol => "https://"
redirect_to :action => "myaction", :protocol => "https://"

每次?

4

1 回答 1

-1

Simply use config.force_ssl = true in your environment configuration.

# config/application.rb
module MyApp
  class Application < Rails::Application
    config.force_ssl = true
  end
end

You can also selectively enable https depending on the current Rails environment. For example, you might want to keep HTTPS turned off on development, and enable it on staging/production.

# config/application.rb
module MyApp
  class Application < Rails::Application
    config.force_ssl = false
  end
end

# config/environments/production.rb
MyApp::Application.configure do
  config.force_ssl = true
end

Behind the scenes, Rails adds the awesome Rack::SSL Rack middleware to your application middleware stack. Rack::SSL automatically filters the request, redirects not-HTTPS requests to the corresponding HTTPS path and applies some additional improvements to make sure your HTTPS request is secure.

于 2012-05-14T14:43:19.987 回答