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 4594064
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:46:30+00:00 2026-05-21T22:46:30+00:00

I’ve made a simple app and I wanted to test pages for 404, 500

  • 0

I’ve made a simple app and I wanted to test pages for 404, 500 etc. http errors. I’ve changed config.consider_all_requests_local to false in my enviroments/development.rb but I’ve still got some problems so I would like to ask you a few questions…

  1. If I type in my bowser something inappropriate like http://localhost:3000/products/dfgdgdgdgfd I still see the old “Unknown action” site. However if I type local ip adress of my computer for ex. http://192.168.1.106:3000/products/dfgdgdgdgfd I can see the 404 error page from public folder. Why is that happening?

  2. I know that if I deploy my little project somewhere than my app will use the production mode and if any error would occure the 404 or 500 page will show up. But what if I want to make those error pages more dynamic ( for ex. rendering error message while using a layout with a list of popular products) or simply redirecting them to the main page?

2.1. The first solution that I found was to use rescue_from method in application controller:

unless Rails.application.config.consider_all_requests_local
   rescue_from Exception, :with => :render_error
   rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
   rescue_from AbstractController::ActionNotFound, :with => :render_not_found
   rescue_from ActionController::RoutingError, :with => :render_not_found
   rescue_from ActionController::UnknownController, :with => :render_not_found
   rescue_from ActionController::UnknownAction, :with => :render_not_found
end
.
.
.
private
def render_error exception
  Rails.logger.error(exception)
  redirect_to root_path
  #or 
  # render :controller=>'errors', :action=>'error_500', :status=>500
end

def render_not_found exception
  Rails.logger.error(exception)
  redirect_to root_path
  #or 
  # render :controller=>'errors', :action=>'error_404', :status=>404
end

… but that code didn’t work at any case.

2.2. The second solution was to place match "*path" , :to => "products#show", :id=>1 (that’s the example main page in my silly app) or match "*path" , :to => "errors#error_404", :id=>1 at the end of the routes.rb file. That code works only for typos like http://192.168.1.106:3000/dfgdgdgdgfd because if I try http://192.168.1.106:3000/products/dfgdgdgdgfd (the controller exists but the action is not found) I still got the 404 page.
I’ve played a bit trying sth like match "*path/*act" , :to => "products#show", :id=>1 or match ":controller(/*act)" , :to => "products#show", :id=>8 but that didn’t work either…

2.3. The third solution was to make controller for errors and a file in initializers folder with this code:

# initializers/error_pages.rb
module ActionDispatch 
  class ShowExceptions 
    protected     
    def rescue_action_in_public(exception) 
       status = status_code(exception).to_s 
       template = ActionView::Base.new(["#{Rails.root}/app/views"]) 
       if ["404"].include?(status) 
         file = "/errors/404.html.erb" 
       else 
         file = "/errors/500.html.erb" 
       end         
       body = template.render(:file => file) 
       render(status, body) 
    end 
  end 
end 

That was quite useful because it would let me to render dynamic erb files but.. it’s not rendering any layout. I’ve tried to change body = template.render(:file => file) to body = template.render(:partial => file, :layout => "layouts/application") but it was only cousing errors.

I know that I’m doing sth wrong and I belive that there is a working solution for those error pages so I hope that you can help…

Cheers.

  • 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-21T22:46:30+00:00Added an answer on May 21, 2026 at 10:46 pm

    In your application controller you need to override this method:

    def method_missing(m, *args, &block)
      Rails.logger.error(m)
      redirect_to :controller=>"errors", :action=>"error_404"
      # or render/redirect_to somewhere else
    end
    

    and then you have to combine it with this code:

    unless Rails.application.config.consider_all_requests_local
      rescue_from Exception, :with => :method_missing
      rescue_from ActiveRecord::RecordNotFound, :with => :method_missing
      rescue_from AbstractController::ActionNotFound, :with => :method_missing
      rescue_from ActionController::RoutingError, :with => :method_missing
      rescue_from ActionController::UnknownController, :with => :method_missing
      rescue_from ActionController::UnknownAction, :with => :method_missing
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload

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.