# Rails 2.0 : handling routing error (Was: fallback to a default controller action)

**URL:** <https://www.ruby-forum.com/t/rails-2-0-handling-routing-error-was-fallback-to-a-default-controller-action/116639>\
**Category:** Rails\
**Created:** [October 8, 2007, 11:29am UTC](https://www.ruby-forum.com/t/rails-2-0-handling-routing-error-was-fallback-to-a-default-controller-action/116639 "2007-10-08T11:29:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabien\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@Fabien\_P](https://www.ruby-forum.com/u/Fabien_P)\
**Post date:** [October 8, 2007, 11:29am UTC](https://www.ruby-forum.com/t/rails-2-0-handling-routing-error-was-fallback-to-a-default-controller-action/116639/1 "2007-10-08T11:29:05Z")

</div>

> 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

I am trying to use this to display the 404 HTML file in case of routing  
error :

rescue\_from ActionController::RoutingError, :with =\> :show\_404

But it never gets called, and I still get a :

No route matches “/foo” with {:method=\>:get}  
vendor/rails/actionpack/lib/action\_controller/routing.rb:1411:in  
`recognize\_path’  
(…)

Any idea ? I am in production environment.

---

<div class="post-metadata">

**Author:** ![Fabien\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@Fabien\_P](https://www.ruby-forum.com/u/Fabien_P)\
**Post date:** [October 8, 2007, 11:43am UTC](https://www.ruby-forum.com/t/rails-2-0-handling-routing-error-was-fallback-to-a-default-controller-action/116639/2 "2007-10-08T11:43:48Z")

</div>

On 8 Oct 2007, at 10:28, Fabien P. wrote:

> ```
> (...)
> 
> ```
> 
> Any idea ? I am in production environment.

Where have you put your rescue\_from ? I haven’t used this much, but  
I’d guess that you’d have to have this in application.rb for this to  
even stand a chance of working for a routing error.

Fred

---

<div class="post-metadata">

**Author:** ![Fabien\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@Fabien\_P](https://www.ruby-forum.com/u/Fabien_P)\
**Post date:** [October 9, 2007, 2:02am UTC](https://www.ruby-forum.com/t/rails-2-0-handling-routing-error-was-fallback-to-a-default-controller-action/116639/3 "2007-10-09T02:02:59Z")

</div>

> Where have you put your rescue\_from ? I haven’t used this much, but  
> I’d guess that you’d have to have this in application.rb for this to  
> even stand a chance of working for a routing error.

I did put it in application.rb, but it doesn’t work ☹

–

> **[Random Thoughts](https://pen.so/)**
>
> Random thoughts about technology, coding, travels and other subjects I enjoy in life.
