# Optional route parameters for resource routes?

**URL:** <https://www.ruby-forum.com/t/optional-route-parameters-for-resource-routes/155259>\
**Category:** Rails\
**Created:** [December 9, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/optional-route-parameters-for-resource-routes/155259 "2008-12-09T22:23:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [December 9, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/optional-route-parameters-for-resource-routes/155259/1 "2008-12-09T22:23:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [December 10, 2008, 3:43am UTC](https://www.ruby-forum.com/t/optional-route-parameters-for-resource-routes/155259/2 "2008-12-10T03:43:40Z")

</div>

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 J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
