Question about "super dynamic" routes, like :reqs => {:id =>

Hi,

I want my app to handle different possibilities for a path. I know I can
easily do this inside my app, as I just evaluate the generic path and
render the desired component.

However, I was wondering if this was possible directly in routes.rb

Suppose I want to handle these three kind of URLs:

//…
//…
//…

Then, maybe I could do something like:

map.connect ‘:state/*path_info’, :controller => ‘states’, :requirements
=> {not State.find(:first, :conditions => ‘name =
‘#{:state}’’).empty?}

That would supposedly look if there was a state with that name, and use
that controller if there was. I’d use a similar approach for the other
routes.

I haven’t tried if it works yet (if it does I’d be extremely surprised
if my example worked!), but if it did, would you recommend doing
something like this or handling it directly inside a controller?

Thanks!

Ivan V.

On 11/23/05, Iván Vega R. [email protected] wrote:

//…
that controller if there was. I’d use a similar approach for the other
routes.

I haven’t tried if it works yet (if it does I’d be extremely surprised
if my example worked!), but if it did, would you recommend doing
something like this or handling it directly inside a controller?

Thanks!

Ivan V.

I doubt it will work since you’re passing :state (the symbol, not the
param value) to State. Even if that did work the way you’re wanting,
it would execute DB queries just to match routes. I’d suggest doing
this in the controller.


rick
http://techno-weenie.net