1

rabl でレンダリングされた JSON 応答の子の数を制限したい

collection @vehicles
attributes :name

child(:positions) do
   attributes :lat, :lon
end

Vehicle has_many の位置と位置は車両に属します。ここで、JSON の最後の位置のみを出力したいと考えています。

アイデアをいただければ幸いです。

4

1 に答える 1

2

私のモデルでも同様の状況があり、これが私がそれをどのように扱うかです。

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
于 2012-06-05T00:18:30.967 に答える