我正在开发一个Rails 3.2.14应用程序,我正在使用Rabl输出API数据。 我想为下面的输出更改根节点(通知)和对象节点(通知)的名称。我怎么能这样做?
{
"total": 1,
"notifications": [
{
"notification": {
"id": 2,
"subject": "Testing",
"body": "Testing",
"created_at": "16 Jan 2014 14:22",
"conversation": 2,
"sender_id": 5,
"sender_name": "Mike Swanson"
}
}
]
}
show.rabl文件:
object false
node(:total) { @output.count }
child(@output) { extends 'api/v1/shared/conversation_rich' }
conversation_rich文件:
attributes :id, :subject, :body
node(:created_at) { |message| message.created_at.strftime("%e %b %Y %H:%M") }
node(:conversation) { |message| message.conversation.id }
node(:sender_id) { |message| message.sender.id }
node(:sender_name) { |message| message.sender.fullname }
更新
事实证明这非常简单。只需添加=> :消息:
child(@output => :messages) { extends 'api/v1/shared/conversation_rich' }
答案 0 :(得分:0)
事实证明这非常简单。只需添加=> :消息:
child(@output => :messages) { extends 'api/v1/shared/conversation_rich' }