Rails,是否可以部分使用 SSL [英] Rails , is it possible use SSL partially
本文介绍了Rails,是否可以部分使用 SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将 http 用于某些请求,而 https 用于像一台 Rails 服务器这样的其他请求
Is it possible to use http for some request and https for other requests for one rails server like
http://i.mysite.com/
和
https://mysite.com/
谢谢
推荐答案
是:
before_filter :https_redirect
def https_redirect
if request.ssl? && !use_https? || !request.ssl? && use_https?
protocol = request.ssl? ? "http" : "https"
flash.keep
redirect_to protocol: "#{protocol}://", status: :moved_permanently
end
end
def use_https?
controller_name == "abc"
end
(我从某个地方获取了此代码,我不记得了,所以我无法提供学分......但我在一个项目中使用它并且它有效).
(I take this code from some place, I don't remember so I can't give the credits... but I use it on a project and it works).
更新:我从 RailsCasts 中获取代码哈哈,感谢 Ryan Bates.
UPDATE: I take the code from a RailsCasts haha so thanks to Ryan Bates.
这篇关于Rails,是否可以部分使用 SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文