Would it be possible to add procs to route definition to set params when generating a route?


in my current project I need to provide a city name as a prefix in
*most* of urls in my app, which acts as a scope for permalinks. I'd
like to avoid manually passing city name to almost every link_to and
redirect_to if possible.

Would it be possible to add to Rails 2.3/3.0 routing system something
similar to default param values, but to actually set these values
using a proc? I.e. for locales you could do something like:

map.with_options :path_prefix => "/:locale", :locale => Proc.new { |
params> params[:locale] = I18n.locale } do |locale|
  locale.resources ....

This would require some changes to *_url helpers, so that it wouldn't
try to assign the first attribute passed to the helper to :locale
param. I'm not sure in what context these procs could be evaluated and
what variables could be passed to them.

I know that there's routiing-filter plugin by Sven Fuchs, but it works
for all routes.

Additionally, having a route like "/posts/:category/:id" - currently
you have to pass "post.category" manually as the first param - with
this addition you could do something like:

map.post "/posts/:category/:id". :category => Proc.new { |params|
params[:category] = params[:id].category }

so that stuff like link_to(post.title, post) would still work.

Any tips if it's even possible to implement something like this with
the Rails 2.3/3.0 routing system?