Forum: Ruby on Rails Modifying output from to_json to exclude table name

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
07c3bbb8300f645e72c6339e3801d5d0?d=identicon&s=25 skt (Guest)
on 2009-03-06 00:01
(Received via mailing list)
Folks,

I have a Meal model and Model.find(:all).to_json returns the following

[{"meal": {"name": "Veggies Lasagna", "id": 1}}, {"meal": {"name":
"Chicken Rice", "id": 2}}, {"meal": {"name": "Noodle Rice", "id": 3}}]

What I want to do is not have the table name (meal) be part of the
output json string i.e. what I want it to output is

[ {"name": "Veggies Lasagna", "id": 1}, {"name": "Chicken Rice", "id":
2}, {"name": "Noodle Rice", "id": 3}]

Any way I can do this? I looked at to_json input options which seem to
let you control the columns that are output but apparently not the
table name.

If you are wondering why I need JSON output in this format, that is
because I want to consume this output from dojo.data.ItemFileReadStore

Thanks for any pointers/help.

-S
07c3bbb8300f645e72c6339e3801d5d0?d=identicon&s=25 skt (Guest)
on 2009-03-06 00:12
(Received via mailing list)
Figured it out.

Have to set ActiveRecord::Base.include_root_in_json = false
This topic is locked and can not be replied to.