如何在rabl模板中的子项中添加父属性?要做这样的事情:
parent: {
attr_1: 'asd',
attr_2: 'dfg',
child: {
attr_3: 6,
attr_from_parent: 'cvb'
}
}
答案 0 :(得分:0)
object @parent
attributes :attr_1, :attr_2
child :child do
attributes :attr_3, :name
node(:attr_from_parent) { @parent.attr_from_parent }
end
您还可以查看http://railscasts.com/episodes/322-rabl?view=asciicast