由于Sintra是一个Rack应用程序,我认为它可以使用Rack方式:
get '/' do
result = true
if result
['200', {'Content-Type' => 'application/json'}, [{result:true}.to_ json]]
else
binding.pry
['500', {'Content-Type' => 'application/json'}, [{result:false}.to _json]]
end
end
它不起作用,它总是返回一个 500
页面,无论变量是 true
还是 false
最佳答案
如果您的应用程序中确实有此文字代码:
{result:true}.to_ json # <<< whitespace that shouldn't be there
那么你的代码将会出现运行时异常(可能缺少方法 to_
或 未知变量或方法 json
),这就是为什么你每次都会收到 500 错误。
关于sinatra - 如何使用 Sinatra 服务 500 个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16194851/