[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

fallthrough routing in a web microframework

Martin DeMello

6/27/2008 10:13:00 PM

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 <martindemello@gmail.com>
Date: Fri, Jun 27, 2008 at 3:06 PM
Subject: fallthrough routing
To: Halcyon Development <halcyon-dev@googlegroups.com>


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

4 Answers

Martin DeMello

6/27/2008 10:23:00 PM

0

On Fri, Jun 27, 2008 at 3:15 PM, Martin DeMello <martindemello@gmail.com> 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

ara.t.howard

6/28/2008 4:41:00 AM

0


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://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Martin DeMello

6/28/2008 7:20:00 AM

0

On Fri, Jun 27, 2008 at 9:41 PM, ara.t.howard <ara.t.howard@gmail.com> wrote:
>
> 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.
>
> 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?

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

ara.t.howard

6/28/2008 3:57:00 PM

0


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://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama