render to_json has_many array display

E

elubin1234

I have an ActiveRecord class with a has_many of another class. All works fine to query the first and add the second with to_json. However, how can i display the class B data in a more precise format?

ss = ShirtSet.select("shirt_sets.id")
render :json => ss.to_json:)include => {:shirt => {:eek:nly => :name}})

[{"id":"SHIRT SET 1","shirts":[{"name":"shirt1"},{"name":"shirt 2"},{"name":"shirt 3"}]}]

when what i really want is:

[{"id":"SHIRT SET 1","shirts":["shirt1","shirt 2","shirt 3"}]

is there a way to easily do that with to_json (maybe the :method helper?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top