我需要强制所有路线 SSL在我的应用程序,除了landing#index
。
在config/application.rb
,我有:
config.force_ssl = true
然后在landing_controller.rb
,我有:
force_ssl :except => :index
然而,所有的路由仍然被重定向到https
。
有谁知道如何有条件地强制SSL在Rails 3.1+应用程序?
解:
以下添加到您Gemfile
:
gem 'rack-ssl-enforcer'
以下添加到您config/application.rb
:
config.middleware.use Rack::SslEnforcer, :except => [ /\/$/ ], :strict => true
我问计算器上类似的问题在这里 ,被告知使用https://github.com/tobmatth/rack-ssl-enforcer 。 我还没有尝试过了还,但根据自述,它的出现解决的某条线路有条件执行SSL您的问题。
与ActiveAdmin 1.0B导轨4,I改性配置/初始化/ active_admin.rb:
config.before_filter :force_ssl_redirect, if: :https_enabled?
force_ssl_redirect
在ActionPack的/ LIB / action_controller /金属/ force_ssl.rb定义,并且是Rails的什么force_ssl
类的方法调用。
https_enabled?
在我application_controller.rb定义:
def https_enabled?
ENV['HTTPS_ENABLED'] == 'true'
end
你可以这样来做:
调节器
force_ssl :except => :index
视图
假设你的索引路径名index_landing_path
<%= link_to 'Landing', index_landing_path, :protocol => 'http' %>