I'm trying to set up a restful route where an Album resource has a singletone Artwork resource. Sounds simple enough:
map.resources :albums do |album| album.resource :artwork, :controller => 'artwork', :format => 'jpg' end
With the above routing config, /albums/xxx/artwork.jpg works as expected.
However, my artwork controller also has an option to resize the image if a :size parameter is given. This also works:
/albums/xxx/artwork.jpg?size=100
However, I want to cache the resized artwork using Rails caching. Adding caches_page :show works and the cached file is saved under public/albums/xxx/artwork.jpg.
But what about when I specify a size? I want these to be cached individually. Specifying size as a query string parameter means the size is ignored when caching takes place (it is always stored as artwork.jpg). What I really need is to be able to move the size parameter into the URL, so it looks something like this:
/albums/xxx/artwork/size.jpg
This would mean page caching does what I want it to do. However I cannot see any easy way of moving size into the URL using map.resource. I can set up a custom route but any restful url helpers take no notice of it. Can anybody help me with this?