开发者

Disable Cookies in Rails 3.x app

Is there a way to disable all cookies for a Rails app? Or preferably on a controller by controlle开发者_如何学Pythonr 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.


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

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

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


If you're using Apache, you can turn probably turn off cookies in the response by using mod_headers, which is a standard apache mod.

Header always unset "Set-Cookie"


You might want to use ActionController::Metal and add any additional modules that you might need.

ActionController::Metal is pretty barebone and skips most of the functionality of a typical ApplicationController including cookies.

You can call ApplicationController.ancestors to get an idea of what is typically included in contrast with ActionController::Metal.ancestors

Here's how I would most likely set it up.

class SimpleController < ActionController::Metal
 #include ...
 #include ...
end

class FirstApiController < SimpleController
 def index
  #Code 
 end
end 

class SecondApiController < SimpleController
 def index
  #Code 
 end
end 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜