How to test 500.html in rails development env?

前端 未结 8 1178
悲哀的现实
悲哀的现实 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:08

    Just do a http://localhost:3000/404 or /500 to access these pages and see how they look like.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-14 06:13

    I think the proper setting to twiddle is this:

    config.action_view.debug_rjs = false
    

    Why it's still labelled rjs isn't entirely clear.

    0 讨论(0)
  • 2020-12-14 06:19

    In addition to setting: config.consider_all_requests_local = false I also needed to set: config.action_dispatch.show_exceptions = true

    0 讨论(0)
  • 2020-12-14 06:21

    None of the proposed solutions worked in my Rails 3 app. The quick and dirty solution for me was to simply hit the error pages directly to see the rendered HTML. For example,

    http://0.0.0.0:3000/404.html
    
    http://0.0.0.0:3000/500.html
    
    0 讨论(0)
  • 2020-12-14 06:31

    The only way I've found to do this so far is to set in development.rb

    config.consider_all_requests_local = false

    Then access the URLs using my local IP address: http://192.168.1.135:3000/blah

    The other settings mentioned don't seem to have any effect.

    0 讨论(0)
提交回复
热议问题