I'm adding jbuilder to a Rails app -- great tool!
I'm getting the list of records I want, but it has extra output I don't want.
This is the jbuilder code:
json.locations @locations do |location|
json.id location.id
json.name location.name
end
The output is:
{
- locations: [
{
id: 1,
name: "Name 1"
},
{
id: 2,
name: "Name 2"
},
What I need is:
[
{
id: 1,
name: "Name 1"
},
{
id: 2,
name: "Name 2"
},
How can I remove the { - locations:
???
Thanks!!
UPDATE:
I'm hoping there is a line of code for jbuilder that would exclude the root.
Can you check if you have the following config?
ActiveRecord::Base.include_root_in_json = false
That should do the trick
Try this instead:
json.array!(@locations) do |location|
json.id location.id
json.name location.name
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With