Render :json question

I am calling “render :json => @buildings” from a Buildings
controller.

It’s returning
[{“building”:{“value”:“114 3rd Ave New York”}},{“building”:
{“value”:“114 1st Pl Brooklyn”}},{“building”:{“value”:“1140 2nd Ave
New York”}},{“building”:{“value”:“1143 2nd Ave New York”}}]

As expected, however, I need the json array to NOT be nested within a
“building” node.

i.e. I need:
[{“value”:“114 3rd Ave New York”}, {“value”:“114 1st Pl Brooklyn”},
{“value”:“1140 2nd Ave New York”}, {“value”:“1143 2nd Ave New York”}]

I have tried passing various options to the render call and other
to_json and as_json variations.

How would I do this?

Thanks, Elliott G

try

ActiveRecord::Base.include_root_in_json = false

ok.

Perfect!

Thanks a ton Eduardo.

On Mar 7, 2:28pm, “Eduardo de O. Hernandes” [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs