# Routes

**URL:** <https://www.ruby-forum.com/t/routes/160428>\
**Category:** Rails\
**Created:** [February 16, 2009, 9:47am UTC](https://www.ruby-forum.com/t/routes/160428 "2009-02-16T09:47:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [February 16, 2009, 9:47am UTC](https://www.ruby-forum.com/t/routes/160428/1 "2009-02-16T09:47:59Z")

</div>

Hi there,

I have a photo gallery wich i paginate with “will\_paginate”. I added  
this line to my routes file, to make “will\_paginate” work with  
friendly url’s:

map.paginated\_gallery ‘gallery/page/:page’, :controller =\>  
‘gallery’, :action =\> ‘index’, :page =\> nil

And it works perfectly. Now when one click any thumbnail of the  
gallery i want to generate friendly url’s like these:

[http://localhost:3000/gallery/page/1/product/49](http://localhost:3000/gallery/page/1/product/49)  
[http://localhost:3000/gallery/page/1/product/50](http://localhost:3000/gallery/page/1/product/50)  
[http://localhost:3000/gallery/page/1/product/51](http://localhost:3000/gallery/page/1/product/51)

So that means that i am in the gallery controller, located at page  
number 1, and viewing thumbnails of the 49(or 50 or 51 etc) product. I  
added this line for that purpose:

map.connect ‘gallery/page/:page/product/:product\_id’, :controller =\>  
‘gallery’, :action =\> ‘index’, product\_id =\> nil

So with this, i can use [http://localhost:3000/gallery/page/1/product/49](http://localhost:3000/gallery/page/1/product/49)  
without any problem… but:

I do not know how to generate the thumbnails links in the correct way,  
i generate them like: \<%= link\_to “something here”, params[:page] + “/  
product/” + product\_picture.id.to\_s %\>  
so when i clicked in the first thumbnail i get a good url like:

[http://localhost:3000/galeria/page/1/product/49](http://localhost:3000/galeria/page/1/product/49)

but when i clicked a second one the url comes like:

[http://localhost:3000/galeria/page/1/product/1/product/52](http://localhost:3000/galeria/page/1/product/1/product/52)

1- Am i generating right the links??  
2- The “map.connect ‘gallery/page/:page/  
product/:product\_id’, :controller =\> ‘gallery’, :action =\> ‘index’,  
product\_id =\> nil” is correct?

Any ideas?

Regards

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [February 16, 2009, 9:59am UTC](https://www.ruby-forum.com/t/routes/160428/2 "2009-02-16T09:59:08Z")

</div>

hi,

ok the i think i found out the answer of my first question: “how to  
generate the links in a correct way”, just:

\<%= link\_to image\_tag(product\_picture.public\_filename  
(:mediano)), :controller =\> “gallery”, :action =\> “index”, :page =\>  
params[:page], :product\_id =\> product\_picture.id %\>

that worked for me.

Now my second question: "The “map.connect ‘gallery/page/:page/  
product/:product\_id’, :controller =\> ‘gallery’, :action =\> ‘index’,  
product\_id =\> nil” is correct? ) i noted that when i want to start  
mongrel it tells me:

“Route segment “:page” cannot be optional because it precedes a  
required segment. This segment will be required.”

Any idea what is this?

regards
