# Fallthrough routing in a web microframework

**URL:** <https://www.ruby-forum.com/t/fallthrough-routing-in-a-web-microframework/141632>\
**Category:** Ruby\
**Created:** [June 28, 2008, 12:17am UTC](https://www.ruby-forum.com/t/fallthrough-routing-in-a-web-microframework/141632 "2008-06-28T00:17:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [June 28, 2008, 12:17am UTC](https://www.ruby-forum.com/t/fallthrough-routing-in-a-web-microframework/141632/1 "2008-06-28T00:17:12Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Fri, Jun 27, 2008 at 3:06 PM  
Subject: fallthrough routing  
To: Halcyon D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

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

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [June 28, 2008, 12:27am UTC](https://www.ruby-forum.com/t/fallthrough-routing-in-a-web-microframework/141632/2 "2008-06-28T00:27:09Z")

</div>

On Fri, Jun 27, 2008 at 3:15 PM, Martin DeMello  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [June 28, 2008, 6:44am UTC](https://www.ruby-forum.com/t/fallthrough-routing-in-a-web-microframework/141632/3 "2008-06-28T06:44:15Z")

</div>

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/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [June 28, 2008, 5:59pm UTC](https://www.ruby-forum.com/t/fallthrough-routing-in-a-web-microframework/141632/4 "2008-06-28T17:59:33Z")

</div>

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/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [June 28, 2008, 9:22am UTC](https://www.ruby-forum.com/t/fallthrough-routing-in-a-web-microframework/141632/5 "2008-06-28T09:22:41Z")

</div>

On Fri, Jun 27, 2008 at 9:41 PM, ara.t.howard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
