0

How to add parent attributes inside its children in rabl template? To do something like this:

parent: {
  attr_1: 'asd',
  attr_2: 'dfg',
  child: {
    attr_3: 6,
    attr_from_parent: 'cvb'
  }
}
Jonas
  • 4,683
  • 4
  • 45
  • 81

1 Answers1

0
object @parent
attributes :attr_1, :attr_2

child :child do
  attributes :attr_3, :name
  node(:attr_from_parent) { @parent.attr_from_parent }
end

You may also have a look at http://railscasts.com/episodes/322-rabl?view=asciicast

ted
  • 5,219
  • 7
  • 36
  • 63
  • This is not working because |parent| is equal to child. Any other ideas? – Jonas Apr 08 '13 at 06:06
  • Thank you for the answer. This is right example, but I oversimplified the question and missed the point. This is my new more exact question: http://stackoverflow.com/q/15878381/625521 appreciate your help. – Jonas Apr 08 '13 at 11:55