render to_json has_many array display

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

  1. elubin1234

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

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 (here). After that, you can post your question and our members will help you out.