【发布时间】:2012-01-17 21:09:31
【问题描述】:
我想像这样创建 JSON:
{
"field1": "value-1",
"field2": "value-2",
"actions": {
"edit": "/edit/action/url"
}
}
使用 rabl。它不适用于 child 方法,我也不能使用 node 来实现 - 出现未知方法错误。那么,是否可以使用 rabl 模板创建自定义子节点?说这样的话:
collection @datas => :datas
attributes :field1, :field2
child :actions do
node :edit do
edit_datas_path :id
end
end
编辑
我选这个:
node :actions do
actions = {}
actions[:edit] = edit_customer_group_path(:id)
node :foo do
foos = {}
foos[:bar] = "hello"
foos
end
actions
end
但下面接受的答案也是正确的。
【问题讨论】:
标签: ruby-on-rails ruby json rabl