Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:21:55+00:00 2026-05-30T18:21:55+00:00

I have this rabl template: object @photo attributes :id child :comments do attributes :id,

  • 0

I have this rabl template:

object @photo
attributes :id
child :comments do
  attributes :id, :body
end

Which gives me this JSON response:

{
  photo: {
    id: 1,
    comments: [
      { 
        comment: {
          id: 1,
          body: 'some comment'
        }
      },
      { 
        comment: {
          id: 2,
          body: 'another comment'
        }
      }
    ]
  }
}

But I want it to look like this:

{
  id: 1,
  comments: [
    { 
      id: 1,
      body: 'some comment'
    },
    { 
      id: 2,
      body: 'another comment'
    }
  ]
}

Why does rabl wrap each element in the array with an extra object called comment. In this way when I access the collection in javascript I have to write:

var comment = image.comments[0].comment

instead of:

var comment = image.comments[0]

I know that if I include :comments in the attributes list for the @photo object it works the way I want, but when I want another level of nested associations for each comment object, there isn’t a way to handle that besides using child, but that gives me the JSON response that I don’t want.

Maybe I’m just misunderstanding the whole thing — can someone explain or help? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:21:56+00:00Added an answer on May 30, 2026 at 6:21 pm

    Got it!

    Create a new file in config/initializers/rabl_config.rb:

    Rabl.configure do |config|
      config.include_json_root = false
      config.include_child_root = false
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this template: # app/views/posts/index.rabl collection @posts => :posts attributes :id, :title, :subject
Have this print output from print_r($theobject); SimpleXMLElement Object ( [@attributes] => Array ( [label]
I have this xml response to which I will do a foreach($response->entry->item as $data)
I have this json object : { msg_id:134, message:Dick, comment:[ { com_id:9, comment:test, msg_id:134,
I have this C# code which converts a dataset to xlsx. Is there a
I have this webpage which shows me some images and some images are on
I have this div which acts a lens in zooming of the image. But
I have this in my object's save class UploadFile < ActiveRecord::Base def save dir
Have this objects and table types: CREATE TYPE Person_typ AS OBJECT ( name CHAR(20),
I have this little code which lists all matches of items that contains the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.