Catching requests for non-existing controllers and actions

Hey :slight_smile:

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 :slight_smile:

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


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

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

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’]


Then, for something like
I get,
@failed_url == ‘chillum/huo/and/more/and/what/not’

  • exactly what I want! :slight_smile: I love it!

Cheers you guys,
Daniel :slight_smile: