On 14 May 2012, at 14:06, Rodrigo Rosenfeld Rosas wrote:

>> I'm not sure what you expect Rails to do here - how does it know to fetch 
>> the JSON cached version if you're relying on the content_type being set by 
>> the render? The whole point of action caching is to avoid calling render.
> 
> I was expecting the relevant headers to be cached alongside with the body 
> content of the response.

That's a longstanding issue - you may want to look at using HTTP caching 
instead which does cache headers. Rails 3.2 is pre-configured with Rack::Cache 
- try removing the action caching code from your controller and look at the API 
docs for stale?, fresh_when? and expires_in. See also the Rails Guide on 
caching:

http://guides.rubyonrails.org/caching_with_rails.html#conditional-get-support

>> We could certainly consider whether :format =>  :json or :format =>  [:html, 
>> :json] would restrict it to those formats (i.e. setup :constraints and 
>> :defaults automatically), however that would have to be with :format in the 
>> path as you can't turn it off without :format =>  false. Please open an 
>> issue to consider this further.
> 
> Thanks! I'll try to figure it out an API that could allow an unformatted URL 
> before opening the issue. If I can't come to any suggestion I'll open the 
> issue with the API you've just mentioned.
> 
> Wouldn't it be possible that "get '/products', format: :json" responded to 
> both '/products' and '/products.json' when a single format is given instead 
> of an array? Of course I mean that action caching should also use the same 
> correct content-type in the response for both URLs.

You can do that now using an empty option in your regexp:

get '/products' => 'products#index', :format => /|json/

This will match /products and /products.json


Andrew White

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to