Saturday, July 29, 2006

Custom URLs with routes.rb

Using the routes.rb file, we can create custom URLs. It is important to note that the following is valid :

map.connect ':permalink', :action=>'list', :controller=>'categories'


whereas the following are not valid:

map.connect ':permalink-:id', :action=>'list', :controller=>'categories'
map.connect ':permalink_id.html', :action=>'list', :controller=>'categories'
map.connect ':permalink-:id.html', :action=>'list', :controller=>'categories'

3 Comments:

At 6:46 AM, Blogger Luigi said...

Can you tell me how it's possible to generate an url with .html without using:

map.connect ':controller/:action/:id/:title.html'

?

Thank you

 
At 11:51 PM, Blogger Nilesh Patkar said...

This comment has been removed by the author.

 
At 11:53 PM, Blogger Nilesh Patkar said...

you can make it in http server level.
If you are using apache then use mod_rewrite and rewrite rules. If you are using webrick then you can check this article

You can also check this project RDR :: Rails Dynamic Routes on rubyforge, which is a little step towards having dynamic routes in rails.
--
Nilesh

 

Post a Comment

<< Home

eXTReMe Tracker