Forum: Ruby on Rails Catching requests for non-existing controllers and actions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3d197df430dbfd0d0b11f23b0a8d3ec9?d=identicon&s=25 Daniel Smedegaard Buus (Guest)
on 2007-03-23 15:57
(Received via mailing list)
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 :)

3d197df430dbfd0d0b11f23b0a8d3ec9?d=identicon&s=25 Daniel Smedegaard Buus (Guest)
on 2007-03-23 16:17
(Received via mailing list)
Well, okay, seems I could've figured it out for myself in the time it
took for me to write the question, LOL :D

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! :) I love it!

Cheers you guys,
Daniel :)
This topic is locked and can not be replied to.