Fallthrough routing in a web microframework

I’ve already asked on the Halcyon list, but if any other
microframework can do this I’d like to know. Essentially I want a
route to fail on a missing controller/action as well as on an
unmatched pattern.

martin
---------- Forwarded message ----------
From: Martin DeMello [email protected]
Date: Fri, Jun 27, 2008 at 3:06 PM
Subject: fallthrough routing
To: Halcyon D. [email protected]

I would like to match /:controller/:action, and if that does not
exist, fallthrough to a “method_missing” action, e.g.

conceptually:

match(/:foo/:bar).to({:controller => ‘:foo’, :action => ‘:bar’})

if not

match(/:foo/:bar).to({:controller => ‘application’, :action =>
‘default’})

params[:foo] and params[:bar] will then be available to /application/
default to let it proceed.

Is this sort of thing possible at all?

martin

On Fri, Jun 27, 2008 at 3:15 PM, Martin DeMello
[email protected] wrote:

I’ve already asked on the Halcyon list, but if any other
microframework can do this I’d like to know. Essentially I want a
route to fail on a missing controller/action as well as on an
unmatched pattern.

Oh, and as for the ever-recommended “what problem are you really
trying to solve” explanation, I have an app driven by a table like

{‘users’ => {
‘list’ => [‘tom’, ‘dick’, ‘harry’],
‘random’ => ‘tom’
}}

so that /users/list returns [‘tom’, ‘dick’, ‘harry’], for instance.
But I also want to override some actions, that is, if my Users
controller defines a list method, I want to use that, if not I want to
return the response from the table.

And as to why I’m doing that, I want to mock a web service to test
apps that call out to it without touching them.

martin

On Jun 27, 2008, at 4:12 PM, Martin DeMello wrote:

I’ve already asked on the Halcyon list, but if any other
microframework can do this I’d like to know. Essentially I want a
route to fail on a missing controller/action as well as on an
unmatched pattern.

martin

you can easily do this in ramaze, simply define

def method_missing *path_info

end

in your base controller class, or put that into a module which is
included in every controller

is this what you are looking for?

a @ http://codeforpeople.com/

On Jun 28, 2008, at 1:19 AM, Martin DeMello wrote:

Thanks, that’s 99% of what I’m looking for - ideally I’d like to match
routes where the controller doesn’t exist either, but I’ll settle for
having empty controllers for all possible choices.

you can do that too with ramaze

Ramaze::Route[ %r/.*/ ] = ‘/application/default’

class ApplicationController < ::Ramaze::Controller

 def default *path_info

 end

end

obviously that route should be added last.

in rails i think all this would require is

map.connect ‘/*path_info’, :controller => ‘application’, :action =>
‘default’

or something very close (not sure if it’s *path_info or /*path_info)
as your last route to map stuff into a default acttion that would
lookup content from the db or something.

cheers.

a @ http://codeforpeople.com/

On Fri, Jun 27, 2008 at 9:41 PM, ara.t.howard [email protected]
wrote:

def method_missing *path_info

end

in your base controller class, or put that into a module which is included
in every controller

is this what you are looking for?

Thanks, that’s 99% of what I’m looking for - ideally I’d like to match
routes where the controller doesn’t exist either, but I’ll settle for
having empty controllers for all possible choices.

martin