# Custom path overriding - routes.rb

**URL:** <https://www.ruby-forum.com/t/custom-path-overriding-routes-rb/58379>\
**Category:** Rails\
**Created:** [April 21, 2006, 1:18am UTC](https://www.ruby-forum.com/t/custom-path-overriding-routes-rb/58379 "2006-04-21T01:18:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grant\_Neufeld](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e9c0ed/32.png) [@Grant\_Neufeld](https://www.ruby-forum.com/u/Grant_Neufeld)\
**Post date:** [April 21, 2006, 1:18am UTC](https://www.ruby-forum.com/t/custom-path-overriding-routes-rb/58379/1 "2006-04-21T01:18:38Z")

</div>

I want to be able to have custom URL paths to some of my data.

For example, I might have some entries in my “item” table like:  
id=1, title=“Test”, path="/test.html", content=“some test content…”  
id=2, title=“Example”, path="/another/example/", content=“some  
example content…”  
id=3, title=“Some more”,  
path="/however\_convoluted/I/want/to/make\_it.whatever", content=“etc.”

With the regular scaffolding and routes.rb setup, I can have paths  
like /item/view/1, /item/view/2, etc., for these examples, but I also  
want to be able to have the /test.html, /another/example/, etc.,  
paths work.

I’d be happy with being able to catch cases where none of the  
map.connect specified routes in routes.rb. I’d then want to do a  
lookup against my item table to see if I have a matching path, setting  
:controller =\> “item”, :action =\> “view”, :id =\> item.id  
in those cases where I do, and letting control pass through to the  
usual “invalid route” error handler when I don’t have an item for the  
path.

So, is there someway to specify a special handler for routes.rb where  
I could have something like:  
map.connect ‘\*’, { |path| my\_block\_of\_functions }  
where the block would be responsible for turning a dictionary of  
{:controller, :action, :id} values or nil if the path isn’t handled?  
Or something along those lines?

It would also be handy to be able to put such a function/block at the  
to of the routes.rb, so I could potentially override any controller  
path, and pass along to the rest of the routes.rb if I don’t have an  
overriding path.

Thanks!
