# 404 page not found error

**URL:** <https://www.ruby-forum.com/t/404-page-not-found-error/134137>\
**Category:** Rails\
**Created:** [April 8, 2008, 7:31am UTC](https://www.ruby-forum.com/t/404-page-not-found-error/134137 "2008-04-08T07:31:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 8, 2008, 7:31am UTC](https://www.ruby-forum.com/t/404-page-not-found-error/134137/1 "2008-04-08T07: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:

```
  def perform_action
    if self.class.action_methods.include?(action_name)
      send(action_name)
      default_render unless performed?
    elsif respond_to? :method_missing
      method_missing action_name
      default_render unless performed?
    elsif template_exists? && template_public?
      default_render
    else
 #the coding was changed for to avoid 404 errors on 06/04/08
 #flash[:notice]="Seems that the page you were looking for does not

```

exist, so you’ve been redirected here."  
redirect\_to :controller=\>‘account’, :action=\>‘login’  
#raise UnknownAction, “No action responded to #{action\_name}”,  
caller  
end  
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:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 8, 2008, 8:02am UTC](https://www.ruby-forum.com/t/404-page-not-found-error/134137/2 "2008-04-08T08:02:32Z")

</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:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 8, 2008, 10:54am UTC](https://www.ruby-forum.com/t/404-page-not-found-error/134137/3 "2008-04-08T10:54:23Z")

</div>

On 8 Apr 2008, at 06:31, Veera S. wrote:

> 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:** ![veeraa2003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@veeraa2003](https://www.ruby-forum.com/u/veeraa2003)\
**Post date:** [April 8, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/404-page-not-found-error/134137/4 "2008-04-08T15:29:35Z")

</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! 🙂
