What is the proper way to have any invalid request fall back to a specific action and controller? That is, instead of seeing an error like those below, I would like control to pass to my main controller action. The error "no route found to match "/foo with {:method=>:get}" is shown if the controller is invalid. The error "No action responded to foo" is shown if the controller is valid but the action isn''t. Many thanks. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 1 Oct 2007, at 13:16, John Lane wrote:> > > What is the proper way to have any invalid request fall back to a > specific action and controller? > > That is, instead of seeing an error like those below, I would like > control to pass to my main controller action. >I think you need to implement rescue_action. This gets called whenever an exception is thrown, so you need to check whether the exception corresponds to the missing action one and then do as appropriate. Rails 2.0 has a much nicer way of dealing with this, since you can do class PostsController < ApplicationController rescue_from FooError, :with => :foo_handler protected def foo_handler end end Fred> The error "no route found to match "/foo with {:method=>:get}" is > shown > if the controller is invalid. > The error "No action responded to foo" is shown if the controller is > valid but the action isn''t. > > Many thanks. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I think you need to implement rescue_action.Thanks Fred. Yes, this works if I put this in my application.rb: def rescue_action(exception) redirect_to :controller => :centre, :action => :index end I guess I ought to also include the code from the original rescue_action that logs the error... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---