On Mar 29, 11:20 am, Dan King
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Hi,
>
> In my Rails 3 app I want to log ''unknown action'' and
''routing error''
> incidences and re-direct to the home page. With this goal in mind, I
> added the following to bottom of my routes.rb file:
>
> match ''*'' => ''home#index''
>
> I thought that this catch-all would re-direct to the home page in case
> of ''unknown action'' or ''routing error''
issues. However, in spite of
> having the catch-all statement, I still get the aforementioned error
> pages rather than being re-directed to the home page. Anyone know why
> the re-direction is not occurring? Thanks.
>
> -Dan
>
I think this is a solution, bear with me for the setup....
I moved an existing static html site to a rails 3 app. I discovered
that I could create a route to catch every static page (e.g.
mysite.com/faq.html). However, that didn''t catch an instance where
someone called mysite.com/faqpage.html (or some other bogus page).
The routes.rb line just above my root :to => "home#index" is this:
match "/:redirect", :to => "home#index"
In other words, if you put something in the url that doesn''t get
caught by other routes above, then I stick that string into :redirect
and pass it to home#index. That allows me to test for it and do
something. In my case, I use the value to find a content page with a
matching keyword. A little crude, but it lets me manage content via a
model, and if for some reason I delete a page that my old static site
wanted (/faq.html for example) then the rails app doesn''t break. It
just loads "faq" into :redirect and calls "home#index".
hope that''s helpful
Kevin
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.