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
Weird Rails Error "Permission Denied: Bin/Rails" for Old Rails Apps
Are There Better Ways to Prevent 'Yield' When No Block Is Passed In
Parallel Http Requests in Ruby
Why Do I Get "No Implicit Conversion of String into Integer (Typeerror)"
Ruby/Rails Image Processing Libraries
How to Validate the Presence of a Belongs to Association with Rails
Paperclip Amazon S3 Setup with Heroku
Ruby Convert String to Method Name
How to Tell Rubocop to Ignore a Specific Directory or File
CSV - Unquoted Fields Do Not Allow \R or \N (Line 2)
Start or Ensure That Delayed Job Runs When an Application/Server Restarts
Ruby: How to Group a Ruby Array
How to Access Class Variables in Ruby 1.9
Polymorphic Association with Multiple Associations on the Same Model
Check If String Contains Any Substring in an Array in Ruby
Rake Assets:Precompile Gets Killed When There Is a Console Session Open in Production