# 404 page not found error

**URL:** <https://discuss.rubyonrails.org/t/404-page-not-found-error/27674>\
**Category:** rubyonrails-talk\
**Created:** [April 8, 2008, 5:31am UTC](https://discuss.rubyonrails.org/t/404-page-not-found-error/27674 "2008-04-08T05:31:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [April 8, 2008, 5:31am UTC](https://discuss.rubyonrails.org/t/404-page-not-found-error/27674/1 "2008-04-08T05:31:58Z")

</div>

Hi Everyone,

I want to redirect the user to login page, when he is trying to use access unavailable page. Usually it throws me a exception error and 404 page.

But here when user got 404 error he will be redirected to login page, I modified the method perform\_action under the file /vendor/rails/actionpack/lib/action\_controller/base.rb as follows:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def perform\_action &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if self.class.action\_methods.include?(action\_name) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;send(action\_name) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default\_render unless performed? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif respond\_to? :method\_missing &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;method\_missing action\_name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default\_render unless performed? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif template\_exists? && template\_public? &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default\_render &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#the coding was changed for to avoid 404 errors on 06/04/08 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#flash[:notice]="Seems that the page you were looking for does not exist, so you\'ve been redirected here." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to :controller=\>'account', :action=\>'login' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#raise UnknownAction, "No action responded to #{action\_name}", caller &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

Its working well shall I override this function in my application controller or in some where my app files cos its now in vendor folder,

regards, veeraa

---

<div class="post-metadata">

**Author:** ![Julian\_Leviston](https://avatars.discourse-cdn.com/v4/letter/j/b5a626/32.png) [@Julian\_Leviston](https://discuss.rubyonrails.org/u/Julian_Leviston)\
**Post date:** [April 8, 2008, 6:01am UTC](https://discuss.rubyonrails.org/t/404-page-not-found-error/27674/2 "2008-04-08T06:01:39Z")

</div>

Why do that? That's silly!

You should simply catch an exception and redirect to another page  
rather than do that... but better to use a before\_filter.

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #3 out NOW! [http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 8, 2008, 8:53am UTC](https://discuss.rubyonrails.org/t/404-page-not-found-error/27674/3 "2008-04-08T08:53:24Z")

</div>

> Hi Everyone,
> 
> I want to redirect the user to login page, when he is trying to use access unavailable page. Usually it throws me a exception error and  
> 404 page.

Yuck. rails 2 has stuff to make this much nicer, just stick

rescue\_from(::ActionController::UnknownAction) {redirect\_to ...} in your application controller

Fred

---

<div class="post-metadata">

**Author:** ![Adam\_Jones](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@Adam\_Jones](https://discuss.rubyonrails.org/u/Adam_Jones)\
**Post date:** [April 8, 2008, 1:21pm UTC](https://discuss.rubyonrails.org/t/404-page-not-found-error/27674/4 "2008-04-08T13:21:37Z")

</div>

> > 
> 
> Yuck. rails 2 has stuff to make this much nicer, just stick
> 
> rescue\_from(::ActionController::UnknownAction) {redirect\_to ...} in your application controller
> 
> Fred

Haha, you are the man Fred, Where would the rails world be without you! 🙂
