Removing Child Root Nodes in Rabl

Removing child root nodes in RABL

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

Removing child root nodes in RABL

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

Removing node from RABL

Rabl allows you to control these children root nodes across all views via an initializer

https://www.digitalocean.com/community/tutorials/scaling-ruby-on-rails-setting-up-a-dedicated-mysql-server-part-2

and then setting the correct combination of the configurations

# config/initializers/rabl_init.rb
require 'rabl'
Rabl.configure do |config|
config.include_json_root = true
config.include_child_root = false
end

This might be a duplicate of these questions

Rabl, remove parent element of children

Removing child root nodes in RABL

RABL child block yields child object instead of parent

When you use collection the child block does not yield the individual objects.
What I would do is split it in two files.

index.json.rabl

collection @listing
extends "app/view/listings/base"

base.json.rabl

object @listing
child :address do |listing|
attribute :number_and_street unless listing.address_hidden?
end

EDIT:
I just noticed you're using the rabl-rails gem. My solution works for 'rabl', I am not too sure about this gem :)



Related Topics



Leave a reply



Submit