【发布时间】:2015-04-16 11:53:55
【问题描述】:
我想在我的 JSON 输出中添加一些关于响应的元数据,但 RABL 将它们插入到处理的集合中。这是我的模板:
views/clients/show.rabl
node(:status) { response.status }
node(:time) { Time.now }
collection @client
attributes :name, :base_url, :city
attribute c_at: :created_at
node(:items_count) { |c| c.items.count }
node(:users_count) { |c| c.users.count }
这给了我以下 JSON 响应:
{"client":{"status":200,"time":"2015-04-16 13:45:46 +0200","name":"This is a test","base_url":"http://test.com","city":"Paris","created_at":"2015-04-15 10:38:44 UTC","items_count":3,"users_count":0}}
这里,status 和 time 信息位于 client 集合中。如何提取它们,以获得以下输出:
{"time":"...","status":200,"client":{...}}
【问题讨论】:
标签: ruby-on-rails json rabl