这个问题与这个SO问题和答案(rails-3-ssl-deprecation)有关 ,它建议使用routes.rb和路由来处理rails 3中的ssl:
resources :sessions, :constraints => { :protocol => "https" }
# Redirect /foos and anything starting with /foos/ to https.
match "foos(/*path)", :to => redirect { |_, request| "https://" + request.host_with_port + request.fullpath }
Run Code Online (Sandbox Code Playgroud)
我的问题是链接使用相对路径(我认为这是正确的术语),一旦我在https页面上,所有其他链接到网站上的其他页面然后使用https.
1)对于不需要https的页面,回到http的最佳方法是什么?我是否必须为所有这些设置重定向(我希望注意)或者有更好的方法.重定向会是这样的:
match "foos(/*path)", :to => redirect { |_, request| "http://" + request.host_with_port + request.fullpath }
Run Code Online (Sandbox Code Playgroud)
2)如果需要重定向回http,我该如何处理我希望所有方法都是http的情况除外?即foos(/*path)适用于所有foos方法.但是说我想要foos/upload_foos来使用ssl.我知道如何要求它
scope :constraints => { :protocol => "https" } do
match 'upload_foos' => 'foos#upload_foos', :via => :post, :as => :upload_foos
end
Run Code Online (Sandbox Code Playgroud)
但是,如果我将http重定向放入foos路径,那么https upload_foos会发生什么?
Rails 3.1+我希望我的url帮助程序使用https协议,而不必在我调用的每个帮助程序中指定它.搜索后我发现了各种各样的方法但没有工作,例如:
ROUTES_PROTOCOL = (ENV["RAILS_ENV"] =~ /development/ ? 'http://' : 'https://')
scope :protocol => ROUTES_PROTOCOL, :path => "/app" do
Run Code Online (Sandbox Code Playgroud)
如何才能做到这一点?