How to add parent attributes inside its children in rabl template (when parent is an array)?

前端 未结 2 1300
花落未央
花落未央 2021-01-15 06:46

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

  some_root_attr: {
    attr_a: \'rgtr\',
    parent: [
      {         


        
相关标签:
2条回答
  • 2021-01-15 06:56

    nesquena posted solution on github: https://github.com/nesquena/rabl/issues/436

    collection @posts
    
    node :categories do |p|
      p.categories.map do |c| 
        partial("categories/show", :object => c).merge(:post_attr => p.post_attr)
      end
    end
    
    0 讨论(0)
  • 2021-01-15 07:01
    object @obj
    attributes :attr_a
    
    child :parents do
      attributes :attr_1
      parent = root_object.dup
      child :child do 
        attributes :attr_3
        node(:attr_from_parent_array_member) { parent.attr_from_parent_array_member }
      end
    end
    

    NB haven't tested

    0 讨论(0)
提交回复
热议问题