2015-09-07 135 views
0

有没有办法让所有redirect_to方法的协议HTTPS? 我知道,我不能指定协议redirect_to的方法,像一个单一的电话:HTTPS协议重定向Rails

redirect to protocol: "https://", controller: "my_controller", action: "my_action" 

那么,有没有一种方法,使所有redirect_to的方法以https协议调用。

+0

我肯定是有轨的方式,但我认为它通常的做法是建立你的愿望在你的网络服务器(例如nginx)配置中实现。 – Felix

回答

0

不,根据我的信息。

您可以使用的解决方案是使用before_filter回调来处理重定向请求将要发生的操作。对于应用程序之外的网址,请特别提及协议的绝对网址。

https://www.securewebaccess.com 

添加过滤器,你要的是行动听HTTPS控制器重定向呼叫,说了更新和销毁games_controller行动。

将此代码放在应用程序控制器或其他地方通用,

def https_redirect 
    redirect_to :protocol => "https://" unless (request.ssl? || request.local?) 
end 

Controller文件:

class GamesController 
    before_filter :https_redirect, :only => ["update","destroy"] 
end