ruby-on-rails – 尝试访问破碎的图片网址时,内部服务器错误500
发布时间:2020-12-16 22:01:34 所属栏目:百科 来源:网络整理
导读:我们有一个rails服务器,使用本教程在此设置自定义404和500页: http://ramblinglabs.com/blog/2012/01/rails-3-1-adding-custom-404-and-500-error-pages 虽然它工作很好,并为各种路径抛出404,它会生成内部服务器错误500,同时尝试访问任何类型的后缀路径,如e
我们有一个rails服务器,使用本教程在此设置自定义404和500页:
http://ramblinglabs.com/blog/2012/01/rails-3-1-adding-custom-404-and-500-error-pages 虽然它工作很好,并为各种路径抛出404,它会生成内部服务器错误500,同时尝试访问任何类型的后缀路径,如en / foo.png,en / foo.pdf,en / foo.xml,… 但是像en / file.foo这样的东西会抛出404.所以只有有效的后缀会抛出500. 路线结束: if Rails.application.config.consider_all_requests_local match '*not_found',to: 'errors#error_404' end application_controller.rb unless Rails.application.config.consider_all_requests_local rescue_from Exception,with: :render_500 rescue_from ActionController::RoutingError,with: :render_404 rescue_from ActionController::UnknownController,with: :render_404 rescue_from ::AbstractController::ActionNotFound,with: :render_404 rescue_from ActiveRecord::RecordNotFound,with: :render_404 end protected def render_404(exception) @not_found_path = exception.message respond_to do |format| format.html { render template: 'errors/error_404',layout: 'layouts/application',status: 404 } format.all { render nothing: true,status: 404 } end end def render_500(exception) logger.fatal(exception) respond_to do |format| format.html { render template: 'errors/error_500',status: 500 } format.all { render nothing: true,status: 500} end end 500出现: Missing template errors/error_404 with {:locale=>[:de,:en],:formats=>[:png],:handlers=>[:erb,:builder,:coffee,:arb,:haml]} 解决方法
我们发现错误.
我们有一个error_controller.rb包含这个: def error_404 @not_found_path = params[:not_found] render template: 'errors/error_404',status: 404 end 我们改变了这个问题来解决这个问题: def error_404 @not_found_path = params[:not_found] respond_to do |format| format.html { render template: 'errors/error_404',status: 404 } end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |