rabl でレンダリングされた JSON 応答の子の数を制限したい
collection @vehicles
attributes :name
child(:positions) do
attributes :lat, :lon
end
Vehicle has_many の位置と位置は車両に属します。ここで、JSON の最後の位置のみを出力したいと考えています。
アイデアをいただければ幸いです。
rabl でレンダリングされた JSON 応答の子の数を制限したい
collection @vehicles
attributes :name
child(:positions) do
attributes :lat, :lon
end
Vehicle has_many の位置と位置は車両に属します。ここで、JSON の最後の位置のみを出力したいと考えています。
アイデアをいただければ幸いです。
私のモデルでも同様の状況があり、これが私がそれをどのように扱うかです。
indexアクションにshowアクションを拡張させます。のvehicles/index.json.rabl
collection @vehicles
extends 'vehicles/show'
vehicles/show.json.rabl
object @vehicle
attributes :name
child @vehicle.positions.first => :position do
attributes :lat, :long
end