Removing child root nodes in RABL

后端 未结 4 1766
情歌与酒
情歌与酒 2020-12-29 22:52

I\'m trying to render a pretty simple data structure using RABL, but I can\'t figure out how to remove the child root nodes properly. Here are my two templates.

Fir

相关标签:
4条回答
  • 2020-12-29 23:22

    This is the usual way of removing the root json (rather than specifying object_root: false)

    config/initializers/rabl_config.rb

    Rabl.configure do |config|
      config.include_json_root = false
    end
    

    Does moving that to there (and restarting rails), fix it?

    0 讨论(0)
  • 2020-12-29 23:30

    On latest versions of Rabl, you have to set this configuration if you want include_root_json to be false in all levels.

    Rabl.configure do |config|
      config.include_json_root = false
      config.include_child_root = false
    end
    
    0 讨论(0)
  • 2020-12-29 23:34

    Try replacing:

        child :files do
          extends 'groups/_file'
        end
    

    with:

        node :files do |group|
          group.files.map do |file|
            partial 'groups/_file', object: file, root: false
          end
        end
    
    0 讨论(0)
  • 2020-12-29 23:43

    just putting it out there, in case you want to apply it for a specific child:

    child :files, :object_root => false do
      extends 'groups/_file'
    end
    
    0 讨论(0)
提交回复
热议问题