"fallback" routes

Hello list!

Is there a way to have a “fallback” route? Like if I have one
:cat,:album,:item connected to AlbumsController.show, let’s say the
:cat,
:album or :item were invalid so other route would try to handle it.

The logic would be like this:

  • Check if there’s an album/cat/item if not;
  • Check if there’s an section/subsection/subsubsection
  • and so on

Of course I could add a string prefix to the route to make it unique
like
this: /pages/:section/* but it wouldn’t be as clean as :section/*.

(Note: I’m not sure on how to handle unlimited arguments in the route
in
the case of the subsections example, I just put * as an way to tell that
there might be a unknown number of subsections, so if someone could also
enlighten-me on this one, I would be grateful!)

Thanks,

Marcelo.

Of course I could add a string prefix to the route to make it unique like
this: /pages/:section/* but it wouldn’t be as clean as :section/*.

(Note: I’m not sure on how to handle unlimited arguments in the route in
the case of the subsections example, I just put * as an way to tell that
there might be a unknown number of subsections, so if someone could also
enlighten-me on this one, I would be grateful!)

Catchall to handle redirects for old site urls

map.connect “*args”, :controller => “url_mapper”, :action => “index”

Then in your method look at: params[:args] to get an array of all the
args (array is built by splitting on /)

-philip

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs