# Generating a path from a route with requirements

**URL:** <https://www.ruby-forum.com/t/generating-a-path-from-a-route-with-requirements/181424>\
**Category:** Rails\
**Created:** [January 11, 2010, 6:40pm UTC](https://www.ruby-forum.com/t/generating-a-path-from-a-route-with-requirements/181424 "2010-01-11T18:40:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [January 11, 2010, 6:40pm UTC](https://www.ruby-forum.com/t/generating-a-path-from-a-route-with-requirements/181424/1 "2010-01-11T18:40:36Z")

</div>

I am trying to generate a path for a route with requirements. The  
route looks like this…

map.courses\_image\_cache ‘/courses/image\_cache’,  
:controller =\> ‘courses’, :action =\> ‘image\_cache’,  
:requirements =\> {  
:cache\_id =\> /\d{8}-\d{4}-\d{5}-\d{4}/,  
:filename =\> /[a-zA-Z0-9\_]+.(jpg|jpeg|png|gif){1}/i }

And I call it as

courses\_image\_cache\_path(:cache\_id =\>  
‘20100111-0332-76263-6402’, :filename =\> ‘letter.png’ )

But the result is the path  
“/courses/image\_cache”

Why does the result NOT include the params?

The params match, but no params in the resulting URL… or is that  
intentional, like the keys to the kingdom?

Ideas? Help?

Martin

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [January 11, 2010, 7:01pm UTC](https://www.ruby-forum.com/t/generating-a-path-from-a-route-with-requirements/181424/2 "2010-01-11T19:01:46Z")

</div>

Martin S. wrote:

> I am trying to generate a path for a route with requirements. The  
> route looks like this…
> 
> map.courses\_image\_cache ‘/courses/image\_cache’,  
> :controller =\> ‘courses’, :action =\> ‘image\_cache’,  
> :requirements =\> {  
> :cache\_id =\> /\d{8}-\d{4}-\d{5}-\d{4}/,  
> :filename =\> /[a-zA-Z0-9\_]+.(jpg|jpeg|png|gif){1}/i }
> 
> And I call it as
> 
> courses\_image\_cache\_path(:cache\_id =\>  
> ‘20100111-0332-76263-6402’, :filename =\> ‘letter.png’ )
> 
> But the result is the path  
> “/courses/image\_cache”
> 
> Why does the result NOT include the params?

Because the route has no way of knowing where you wanted the params.  
Perhaps you wanted ‘/courses/image\_cache/:filename/:cache\_id’ in your  
map statement?

> The params match, but no params in the resulting URL… or is that  
> intentional, like the keys to the kingdom?
> 
> Ideas? Help?
> 
> Martin

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [January 11, 2010, 7:06pm UTC](https://www.ruby-forum.com/t/generating-a-path-from-a-route-with-requirements/181424/3 "2010-01-11T19:06:22Z")

</div>

You are absolutely right.
