dangerwillrobinsondanger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-23 23:39 UTC
Quick routes question...
I have
# This is a catch-all for routes that don''t exist, visitor is
redirected to home page.
ActionController::Routing::Routes.draw do |map|
map.connect '':controller/:action/:id''
map.connect ''*path'', :controller =>
''home''
end
in my routes.rb file.
This works fine to redirect to the home page if somebody types a wrong
or missing address into the web browser.
But it doesn''t change the url/uri displayed in the browser.
How can I change the url/uri to display what it should be? (in this
case, domain followed by /home)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
dangerwillrobinsondanger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-23 23:52 UTC
Re: Quick routes question...
Nevermind, I''ve found a simple solution that works:
I''ve simply made the catch-all route controller/action go to a
controller where I def''d an action method that creates a flash message
and redirects to the home page.
In routes.rb:
# This is a catch-all for routes that don''t exist, visitor is
redirected to home page.
ActionController::Routing::Routes.draw do |map|
map.connect '':controller/:action/:id''
map.connect ''*path'', :controller =>
''home'', :action =>
''catcher''#:controller => ''home'', :action
=> ''index''
end
In the corresponding controller:
def catcher
flash[:notice] = ''Seems that the page you were looking for does
not exist, so you\''ve been redirected here.''
redirect_to :action => ''index''
end
It''s not the most sophisticated thing but it works.
Does anybody know the param to include in my flash message to display
the originally requested address?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On Aug 23, 2007, at 6:39 PM, dangerwillrobinsondanger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> map.connect ''*path'', :controller => ''home''You could route this to a "redirect_home" action that calls redirect_to /home --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
dangerwillrobinsondanger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-24 00:14 UTC
Re: Quick routes question...
Ah, Thanks Mr. Ivey, but it looks like my watery brain kicked in just minutes before your post! I already came to that conclusion. That said, I can see where adding loggin for this catcher method could generate useful SEO data for site features or simply routes that *should* be added! Of course it is also a good way to catch malicious visitors that should be banned in the htaccess file. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---