[英]Rails 500 error showing blank page for PUT request
I have setup custom error pages in my rails app. 我在Rails应用程序中设置了自定义错误页面。
application.rb application.rb中
config.exceptions_app = self.routes
routes.rb 的routes.rb
get '404', to: 'application#page_not_found'
get '422', to: 'application#server_error'
get '500', to: 'application#server_error'
application_controller.rb application_controller.rb
def page_not_found
respond_to do |format|
format.html { render template: 'errors/not_found_error', layout: 'layouts/application', status: 404 }
format.all { render nothing: true, status: 404 }
end
end
def server_error
respond_to do |format|
format.html { render template: 'errors/internal_server_error', layout: 'layouts/error', status: 500 }
format.all { render nothing: true, status: 500}
end
end
My custom 500 error page shows up fine when I do a GET request that throws the error but when I submit a form that triggers a NoMethodError, so a PUT request, I just get a blank page. 当我执行引发错误的GET请求时,但是当我提交触发NoMethodError的表单时,我的自定义500错误页面显示得很好,所以在PUT请求中,我只会得到一个空白页面。
Any ideas why the 500 error page displays correctly for a GET request but not for a PUT request? 有什么想法为什么500错误页面对于GET请求而不是PUT请求正确显示?
I tried changing the server_error
method to 我尝试将server_error
方法更改为
def server_error
render template: 'errors/internal_server_error', layout: 'layouts/error', status: 500
end
but this didn't seem to help. 但这似乎没有帮助。
Let me know if I can provide more code, I'm not sure how to troubleshoot this. 如果可以提供更多代码,请告诉我,我不确定如何解决此问题。
use match
and via
on your routes.rb to route all types of HTTP requests to custom error actions 在您的route.rb上使用match
和via
将所有类型的HTTP请求路由到自定义错误操作
# error routes
match '/404' => 'application#page_not_found', :via => :all
match '/422' => 'application#unprocessable_entity', :via => :all
match '/500' => 'application#server_error', :via => :all
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.