Forum: Ruby on Rails Optional route parameters for resource routes?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
328f0bb678423fcea01ebe3b0edc74e6?d=identicon&s=25 Ben Johnson (benjohnson)
on 2008-12-09 22:23
I have the following URL:

/images/1.jpg?size=500

Where images is a resource setup via map.resources :images. I want to
take advantage of caching, and caching ignores parameters. So I need to
make size optional in the url:

/images/1/500.jpg

Something like that where the size can be built into the URL. I looked
through all of the map.resources documentation and couldn't find
anything to do this. Any ideas how I can accomplish this?

Thanks for your help.
6fabb84e727dee98d1277df56458cbac?d=identicon&s=25 Andrew Bloom (Guest)
on 2008-12-10 03:43
(Received via mailing list)
map.resources :images, :member => [:500, :1000]

will map to 2 methods in your controller, but I think you might have
problems giving ruby method names that start with numbers.

you probably just have to make a specially entry in your routes file,
something like this:

map.cached_image '/images/:id/:size', :controller => "images", :action
=> "show"

in your show method just check for the presence of :show in the params
and respond appropriately.

On Dec 9, 3:23 pm, Ben Johnson <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.