Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom Error Page - Ruby on Rails
    text
    copied!<p>I am trying to setup a custom error page in my website. I am following the guidelines at<a href="http://www.perfectline.ee/blog/custom-dynamic-error-pages-in-ruby-on-rails" rel="noreferrer">PerfectLine Blog</a>. </p> <p>It works in the case where the controller exists, but the id does not exist. For example, I have a blog controller and id 4 does not exist. It shows the custom error page</p> <p>But it does not exist in the case, where controller itself does not exist. For example, if I type some random controller with a numeric id does not gets caught by the methods I have setup in the application controller to re-route the custom error pages. In this case, I get an </p> <p><code>ActionController::RoutingError (No route matches "/randomcontrollername"):</code> </p> <p>in the terminal and the default error page that comes with rails.</p> <p><strong>application_controller.rb</strong></p> <pre><code>class ApplicationController &lt; ActionController::Base protect_from_forgery unless Rails.application.config.consider_all_requests_local rescue_from Exception, :with =&gt; :render_error rescue_from ActiveRecord::RecordNotFound, :with =&gt; :render_not_found rescue_from ActionController::RoutingError, :with =&gt; :render_not_found rescue_from ActionController::UnknownController, :with =&gt; :render_not_found rescue_from ActionController::UnknownAction, :with =&gt; :render_not_found end private def render_not_found(exception) render :template =&gt; "/error/404.html.erb", :status =&gt; 404 end def render_error(exception) render :template =&gt; "/error/500.html.erb", :status =&gt; 500 end end </code></pre> <p>Could you please help me. Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload