我已经成功构建了一个api,你可以看到here,代码如下。我需要将对象列为嵌套数组而不是对象数组,但我无法弄明白。
API / V1 / plaques.rb
SELECT distinct u2.id,
CASE
WHEN
CAST(DATEDIFF(minute, u1.usa_start_datetime::timestamp,u1.usa_end_datetime::timestamp) * 1.00 as FLOAT) < 1.00
THEN 1.00 END as fsess_hr,
我得到了什么:
module API
module V1
class Plaques < Grape::API
include API::V1::Defaults
resource :plaques do
desc 'Return all Plaques'
get '', root: :plaques do
Plaque.all
end
desc 'Return a Plaque'
params do
requires :id, type: String, desc: 'ID of Plaque'
end
get ':id', root: 'plaque' do
Plaque.where(id: permitted_params[:id]).first!
end
end
end
end
end
我需要什么:
[
{
"veteran_first": "Alexis",
...
}
]
答案 0 :(得分:1)
此代码返回您想要的JSON:
get '', root: :plaques do
{ items: Plaque.all }
end