How to test 500.html in rails development env?

前端 未结 8 1238
悲哀的现实
悲哀的现实 2020-12-14 05:53

I want to test the 500 error pages in my Rails app using the development environment.

I already tried this in config/environments/development.rb:

8条回答
  •  孤街浪徒
    2020-12-14 06:10

    You should add the below lines to the application_controller,

    unless  ActionController::Base.consider_all_requests_local
        rescue_from Exception, :with => :render_500
        if  ActiveRecord::RecordNotFound
          rescue_from Exception, :with => :render_404
        end
        rescue_from ActionController::RoutingError, :with => :render_404
        rescue_from ActionController::UnknownController, :with => :render_404
        rescue_from ActionController::UnknownAction, :with => :render_404
    end
    

    Then try running with the below settings.

    config.action_controller.consider_all_requests_local = false in config/environments/development.rb:

    It will work. Please dont forget to write the function in application_controller.rb to render the layout for each of the error messages.

提交回复
热议问题