【发布时间】:2012-09-05 17:14:53
【问题描述】:
如果我在 RABL 中使用 node() 方法创建一个子节点,如何控制呈现的属性?
JSON 输出是这样的:
[
{
"location": {
"latitude": 33333,
"longitude": 44444,
"address": "xxxxxxx",
"title": "yyyy",
"url": "http://www.google.com",
"rate": {
"created_at": "2012-09-02T11:13:13Z",
"id": 1,
"location_id": 1,
"pair": "zzzzzz",
"updated_at": "2012-09-02T12:55:28Z",
"value": 1.5643
}
}
}
]
我想去掉 created_at、updated_at 和 location_id 属性。
我的视图文件中有这个:
collection @locations
attributes :latitude, :longitude, :address, :title, :url
node (:rate) do
|location| location.rates.where(:pair => @pair).first
end
我尝试使用部分和“扩展”方法,但它完全搞砸了。另外,我尝试向块中添加属性,但没有成功(输出与属性中指定的一样,但没有显示每个属性的值)。
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby json rabl