rabl
rabl copied to clipboard
wrap child inside a node
currently I have something like this
child :test do
#
end
child :test2 do
#
end
What I'm trying to do is wrapping all of those in a node. And what I tried is below but it doesn't work at all
node :custom-node do
child :test do
#
end
child :test2 do
#
end
end
I see what you are trying to do but you can't nest child inside node in that way. One option is to use a partial. You could do:
# _test.rabl
child :test do
#
end
child :test2 do
#
end
and then
node :custom-node do
partial("path/to/test", :object => @foo)
end
Should potentially do the trick.
+1 :) json-api in mind
If I'm not wrong, the current workaround prevents from caching the partial. Following:
addresses/show.json.rabl:
cache @object
attributes :id, :address, :zip, :phone
node(:links) do |address|
partial('addresses/children', object: address)
end
_addresses/children.json.rabl:
cache @object.country
child(:country) do |country|
attributes :id, :name
end
does not work. @object.country updates are ignored.
Please, any help is apreciated.