# Resource routes: optional path components

**URL:** <https://www.ruby-forum.com/t/resource-routes-optional-path-components/194853>\
**Category:** Rails\
**Created:** [September 12, 2010, 12:16pm UTC](https://www.ruby-forum.com/t/resource-routes-optional-path-components/194853 "2010-09-12T12:16:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [September 12, 2010, 12:16pm UTC](https://www.ruby-forum.com/t/resource-routes-optional-path-components/194853/1 "2010-09-12T12:16:51Z")

</div>

I have a model, Image, with paperclip attachments. The necessary routes  
are currently simply defined by

resources :images

As each image is available in different sizes (styles, really), paths  
effectively look like this

/images/1.png?size=thumb

Which isn’t pretty at all. I’d rather have

/images/1.png (for the default size)  
/images/1/thumb.png

To get this, I’ve defined my routes like this

resources :images  
get ‘images/:id(/:size)(.:format)’ =\> ‘images#show’, :as =\> :image

The second line overwrites the image\_path and image\_url helpers  
generated by the first line. Is there another solution that doesn’t  
involve overwriting and makes resources generate the size routes? One  
important constraint is that I need the :size option on #image\_path; it  
would not help to have additional routes with different names.

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [September 12, 2010, 2:30pm UTC](https://www.ruby-forum.com/t/resource-routes-optional-path-components/194853/2 "2010-09-12T14:30:21Z")

</div>

Hey,

have you tried match? I’m using it and still can use \_path and \_url  
without a problem.

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [September 12, 2010, 3:07pm UTC](https://www.ruby-forum.com/t/resource-routes-optional-path-components/194853/3 "2010-09-12T15:07:11Z")

</div>

On Sunday 12 September 2010, Heinz S. wrote:

> Hey,
> 
> have you tried match? I’m using it and still can use \_path and \_url  
> without a problem.

I’m sorry if I gave the wrong impression, I can still use all the \_path  
and \_url helpers. It’s just that I’m looking for a more elegant  
solution.

Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)
