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_jsoninclude => {:shirt => {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?)
ss = ShirtSet.select("shirt_sets.id")
render :json => ss.to_jsoninclude => {:shirt => {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?)