Daniel Smedegaard Buus
2007-Mar-23 14:52 UTC
Catching requests for non-existing controllers and actions
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Smedegaard Buus
2007-Mar-23 15:13 UTC
Re: Catching requests for non-existing controllers and actions
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
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,
I get,
@failed_url == ''chillum/huo/and/more/and/what/not''
- exactly what I want! :) I love it!
Cheers you guys,
Daniel :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---