render to_json has_many array display

Discussion in 'Ruby' started by elubin1234@gmail.com, May 5, 2012.

  1. Guest

    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?)
    , May 5, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juan Pablo Romero Méndez

    What do you guys think about adding a method "to_json"

    Juan Pablo Romero Méndez, Sep 12, 2011, in forum: Python
    Replies:
    0
    Views:
    251
    Juan Pablo Romero Méndez
    Sep 12, 2011
  2. Replies:
    2
    Views:
    106
    Eero Saynatkari
    Dec 12, 2005
  3. treefrog

    Rails: has_many issue

    treefrog, Feb 6, 2006, in forum: Ruby
    Replies:
    1
    Views:
    157
    Eric Hodel
    Feb 6, 2006
  4. Blackie
    Replies:
    1
    Views:
    400
    Blackie
    Oct 25, 2007
  5. Fritz Trapper

    to_json / to_xml: where to find?

    Fritz Trapper, Sep 20, 2010, in forum: Ruby
    Replies:
    1
    Views:
    118
    Michael Fellinger
    Sep 20, 2010
Loading...

Share This Page