3

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

When my controller returns 304 result, the render_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.

elado
  • 8,510
  • 9
  • 51
  • 60
  • Do you really need components? Because 99% of the times components are a bad idea. It seems to me like you could use a shared response view just as easily in this case. – Martijn Sep 03 '12 at 07:44

0 Answers0