我在Rails 3中使用了render_component,https://github.com/vhochstein/render_component。
当我的控制器返回304结果时,render_component失败并显示以下错误:
undefined method `redirect_url' for []:Array
在这一行:
response = component_response(options, true)[2]
** if response.redirect_url **
redirect_to response.redirect_url
else
render :text => response.body, :status => response.status
end
原因是因为controller.dispatch(action, request)
(component_response
的结果)返回一个数组:
[304, {"ETag"=>"....", "Cache-Control"=>"max-age=0, private, must-revalidate"}, []]
而不是看起来像200的结果:
[200, {"Content-Type"=>"text/html; charset=utf-8", "ETag"=>"\"...\"", "Cache-Control"=>"max-age=0, private, must-revalidate }, #<ActionDispatch::Response:0x007f8eee1918b8 @writer=...
尝试将request_env["Cache-Control"] = "no-store, no-cache, must-revalidate"
添加为ActionDispatch::Request
的标题,但没有运气。我检查了控制器收到的标题。