Routes

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/50
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
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

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

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

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