Custom path overriding - routes.rb


#1

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!