Using rails (4.0.2)
Using rails-api (0.1.0)
当rails-api出现像500这样的错误时,它会在响应中抛出一堆html,尽管所有其他请求都将输出格式化为json。
有什么方法可以从响应中删除html吗?一个简单的500响应,并且日志中的堆栈跟踪将是很好的。
更新:我已从公用文件夹中删除了以下文件:
404.html
422.html
500.html
但是在响应中仍然会得到html。
发布于 2019-06-10 01:15:52
默认情况下,您可以告诉路由返回JSON
namespace :api, defaults: {format: :json} do
namespace :v1 do
namespace :items do
get :all
end
end
end
然后在你的控制器中,
render json: { json_structure: true }, status: :internal_server_error
如果我是你,我会遵循像this guide这样的东西,以确保你已经完成了使标准rails应用程序成为应用程序编程接口的所有必要步骤。
https://stackoverflow.com/questions/21291139
复制相似问题