强制 HTTP 响应在 Rails 中返回状态 200 [英] Forcing HTTP Response to return Status 200 in Rails

查看:44
本文介绍了强制 HTTP 响应在 Rails 中返回状态 200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了我返回 500 的严重情况外,您如何强制您的请求返回状态 200?目前,我遇到了这样一个问题:我的客户不断收到 411(未指定长度)的状态代码,这导致我的测试框架出现问题.

How do you force your requests to return status 200 except for serious cases where I return 500? Currently, I am running into the issue where my client keeps getting a status code of 411 (length not specified) and this is causing issues with my test framework.

有没有办法在 Rails 控制器中手动指定返回状态?

Is there a way to manually specify your return status in maybe a Rails controller?

更具体地说,我知道你可以使用

More specifically I know that you can use

:状态

但是在使用时我应该把它放在哪里

but where do I place that when using

format.json { 渲染 :json=>final_obj}

format.json { render :json=>final_obj}

在 POST 后返回 HTTP 响应?

to return a HTTP response after a POST?

推荐答案

render status: 200, json: @controller.to_json

这篇关于强制 HTTP 响应在 Rails 中返回状态 200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆