rabl icon indicating copy to clipboard operation
rabl copied to clipboard

wrap child inside a node

Open nXqd opened this issue 12 years ago • 3 comments

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

nXqd avatar Mar 06 '13 12:03 nXqd

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.

nesquena avatar Mar 06 '13 18:03 nesquena

+1 :) json-api in mind

waiting-for-dev avatar Nov 21 '14 12:11 waiting-for-dev

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.

waiting-for-dev avatar Feb 10 '15 12:02 waiting-for-dev