2015-04-16 58 views
0

我想在JSON輸出中添加一些關於響應的元數據,但是RABL會將它們插入到已處理的集合中。這裏是我的模板:從集合中提取RABL節點

的意見/客戶/ 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}} 

這裏,statustime信息是client內採集。我如何提取它們,以得到如下輸出:

{"time":"...","status":200,"client":{...}} 

回答

0

找到它了。這個神奇來自object false。這是答案。

object false 

node(:status) { response.status } 
node(:time) { Time.now } 

child @client do 
    attributes :name, :base_url, :city 
    attribute c_at: :created_at 

    node(:items_count) { |c| c.items.count } 
    node(:users_count) { |c| c.users.count } 
end 

希望它會有所幫助。