Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4612692
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:26:14+00:00 2026-05-22T01:26:14+00:00

Is it possible to show different error pages based on the controller?

  • 0

Is it possible to show different error pages based on the controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:26:14+00:00Added an answer on May 22, 2026 at 1:26 am

    For Rails < 3.0.

    Yes, it is possible. I use this method in my application controller to render 404 message:

    def render_optional_error_file(status_code)
      status = interpret_status(status_code)[0,3]
      if status == "404"
        render :template => "/errors/404.html.erb", :status => status
      else
        render :template => "/errors/error.html.erb", :status => status
      end
    end
    

    So, the only thing you need to do is to write this method for each controller, or you can change render line to something like this:

    render :template => error_page, :status => status
    

    and add method:

    def error_page
      "/errors/404.html.erb"
    end
    

    Then you only need to write error_page method in each controller, where you want to change default error page.

    EDIT:
    Ups, I’ve just noticed that this method is deprecated in Rails 3. So there should be another way of doing it.

    For Rails >=3.0:

    Here is one example solution for this. Just add:

    rescue_from ActionController::RoutingError, :with => :render_404
    

    and add render_404 method:

    def render_404
      render :file => "errors/404.html.erb", :status => 404
    end
    

    Or if you want to add 404.html.erb view for each controller without modifing controllers code, you can write it like this:

    def render_404
      render "404.html.erb", :status => 404
    end
    

    I think it should look for this error file inside current controller’s view directory. I didn’t check it, but I think it should work. But remember to include 404.html.erb file in each controller’s view directory. Otherwise there could be an error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone, I am trying to hide/show different html elements (div, etc...) based on
Is it possible to show multiple lines of text in grid cells using the
Would it be possible to show an image in full screen mode using silverlight.
Is it possible to show other processes in progress on an Oracle database? Something
Is it possible to show line numbers in the Developer Center when editing xslt
Is it possible to show the typical iPhone maps annotation/callout bubble (MKAnnotation), on something
Is it possible to show a tooltip without making a link? For example, I
Is it possible to show any part of image in img tag (with pixels)
I am doing an android applicaiton and I know its possible to show or
With silverlight 4.0, it is possible to show a live video of the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.