Rails resce_from setting error page

Source: Internet
Author: User

1. If the activerecord find method is set, no error is returned. Call a method to display the 404 page.

class ApplicationController < ActionController::Base  rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found  def record_not_found    render ‘record_not_found‘    # ....    true  endend

2. Set 500 page

rescue_from RuntimeError, with: :render_errordef render_error     render ‘error_500‘, status: 500, layout: ‘public‘end

3. For other error pages, you can write them to a method.

def self.rescue_errors    rescue_from Exception, with: :render_error    rescue_from RuntimeError, with: :render_error    rescue_from ActionController::UnknownController, with: :render_not_found    rescue_from ActionController::UnknownAction, with: :render_not_foundendrescue_errors unless Rails.env.development?




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.