开发者

Rails 3 render_component can't handle 304? / Force ActionDispatch::Request to avoid cache

I use render_component, https://github.com/vhochstein/render_component in Rails 3.

When my controller returns 304 result, the r开发者_运维问答ender_component fails with this error:

undefined method `redirect_url' for []:Array

on this line:

response = component_response(options, true)[2]

** if response.redirect_url **
  redirect_to response.redirect_url
else
  render :text => response.body, :status => response.status
end

The reason is because controller.dispatch(action, request) (result of component_response) returns an array with:

[304, {"ETag"=>"....", "Cache-Control"=>"max-age=0, private, must-revalidate"}, []]

instead of the 200 result which looks like:

[200, {"Content-Type"=>"text/html; charset=utf-8", "ETag"=>"\"...\"", "Cache-Control"=>"max-age=0, private, must-revalidate }, #<ActionDispatch::Response:0x007f8eee1918b8 @writer=...

Tried to add request_env["Cache-Control"] = "no-store, no-cache, must-revalidate" as a header to the ActionDispatch::Request but no luck. I checked the header is received by the controller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜