# Catching requests for non-existing controllers and actions

**URL:** <https://www.ruby-forum.com/t/catching-requests-for-non-existing-controllers-and-actions/89896>\
**Category:** Rails\
**Created:** [March 23, 2007, 3:57pm UTC](https://www.ruby-forum.com/t/catching-requests-for-non-existing-controllers-and-actions/89896 "2007-03-23T15:57:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 23, 2007, 3:57pm UTC](https://www.ruby-forum.com/t/catching-requests-for-non-existing-controllers-and-actions/89896/1 "2007-03-23T15:57:58Z")

</div>

Hey 🙂

I’m trying to achieve CMS-like functionality with pages, content\_slots  
and content\_providers.

Basically, there are a number of “static” pages in the application,  
“static” meaning there are controllers with actions that service  
requests like /store/items/show/43534.

What I want to do, is offer the possibility to add pages, and urls,  
that “aren’t there” in this sense - like if I wanted to add a /store/  
news page even if there’s no NewsController, and then have a  
PageController (or something similar) that receives all requests that  
don’t have a matching “static” controller & action. I would like this  
to be invisible to the user, meaning that redirecting from /store/news  
to /dynamic\_pages/3 wouldn’t be so nice.

I first though about implementing a method missing in application.rb,  
but of course there’s the whole routing issue - with no route, no  
controller is instantiated, and thus application.rb isn’t loaded  
either. Silly attempt 🙂

How would you guys go about doing this? I would be very interested in  
any useful feedback 🙂

Cheers,  
Daniel

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 23, 2007, 4:17pm UTC](https://www.ruby-forum.com/t/catching-requests-for-non-existing-controllers-and-actions/89896/2 "2007-03-23T16:17:01Z")

</div>

Well, okay, seems I could’ve figured it out for myself in the time it  
took for me to write the question, LOL 😃

Anyways, what I did was add this to the end of routes.rb:

# Catch all that wasn’t routed, and send it to the dynamic page

renderer:  
map.connect ‘\*failed\_url’,  
:controller =\> ‘store/page’,  
:action =\> ‘index’

And the, in my store/page\_controller.rb:

class Store::PageController \< ApplicationController

def index  
@failed\_url = request.parameters[‘failed\_url’]  
end

end

Then, for something like  
[http://localhost/chillum/huo/and/more/and/what/not](http://localhost/chillum/huo/and/more/and/what/not),  
I get,  
@failed\_url == ‘chillum/huo/and/more/and/what/not’

- exactly what I want! 🙂 I love it!

Cheers you guys,  
Daniel 🙂
