Nodes can not be nested #203

Closed
tilo2 opened this Issue Mar 29, 2012 · 4 comments

3 participants

@tilo2

Rabl 0.6.5

nesting node-statements inside a json.rabl template does not seem to generate the expected output:

node :outer do 
  node :attr1 do 
     "something"
  end
  node :attr2 do
    "different"
  end
end

I'd expect:

 "outer": {
   "attr1": "something",
   "attr2": "different",
  },

but I get this:

"outer": [
    {
        "name": "attr1",
        "options": { },
        "block": { }
    },
    {
        "name": "attr2",
        "options": { },
        "block": { }
    }

],
@nesquena
Owner

It's because the node block is evaluated and the return result is the value. So basically whatever is returned by node is what you see. It's meant for more manual construction, i.e:

node :outer do 
  { :attr1 => "something", :attr2 => "different" }
end

I think having node work this way (just getting the return value of the block) allows for the most flexible use. I can see why you'd like that the other way though as well. Perhaps there's a way to support both.

@tilo2

and it picks up other nodes which are parallel to :outer , and sticks them inside :outer - makes them parallel to :attr1, :attr2

@tilo2
@databyte
Collaborator

I'm going to close this and move the discussion into #177

You can already nest child and in discussing #177, it should become more flexible in allowing nesting without depending on a root object.

@tilo2 - you may also be interested in reading #216 as your need to attach pagination to the root collection is what that issue will ultimately address for you.

@databyte databyte closed this Apr 6, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment