如果您不想依赖分叉插件,您可以覆盖 ssl_allowed? 在您的控制器中:
class ApplicationController < ActionController::Base
...
private
def ssl_allowed?
true
end
end
编辑:这不符合我的想法。它不会为未指定 ssl_required 的页面禁用重定向到 http,而是将整个重定向过程缩短为什么都不做。这真是太糟了。编码:
def ensure_proper_protocol
return true if ssl_allowed?
if ssl_required? && !request.ssl?
redirect_to "https://" + request.host + request.request_uri
flash.keep
return false
elsif request.ssl? && !ssl_required?
redirect_to "http://" + request.host + request.request_uri
flash.keep
return false
end
end
添加 ssl_allowed? 只有当代码改为:
def ensure_proper_protocol
if ssl_required? && !request.ssl?
redirect_to "https://" + request.host + request.request_uri
flash.keep
return false
elsif request.ssl? && !ssl_required? && !ssl_allowed?
redirect_to "http://" + request.host + request.request_uri
flash.keep
return false
end
end