在Rails 3.x应用程序中禁用Cookies [英] Disable Cookies in Rails 3.x app

查看:50
本文介绍了在Rails 3.x应用程序中禁用Cookies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以禁用Rails应用程序的所有cookie?还是最好在每个控制器的基础上?我的问题是关于Adobe Lightroom插件对Rails JSON API的访问.显然,服务器响应中存在任何cookie数据都会在Lightroom中导致错误.

Is there a way to disable all cookies for a Rails app? Or preferably on a controller by controller basis? My problem is regarding access of a Rails JSON api by an Adobe Lightroom plugin. Apparently the presence of any cookie data in the response from the server causes an error in Lightroom.

推荐答案

在要避免cookie的控制器中,添加以下内容:

In the controller you want to avoid cookies, add this:

after_filter :skip_set_cookies_header

def skip_set_cookies_header
  request.session_options = {}
end

如果您有一组api控制器,请在api_controller类中进行设置,然后让其他控制器继承api_controller.

If you have a set of api controllers, set this in a api_controller class and let your other controllers inherit the api_controller.

由于会话选择为空,因此跳过设置Set-Cookie标头.

This skips setting Set-Cookie header since the session opts is empty.

这篇关于在Rails 3.x应用程序中禁用Cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆