Rails - JSON object with an array?

Posted by AnApprentice on Stack Overflow See other posts from Stack Overflow or by AnApprentice
Published on 2010-12-21T22:51:27Z Indexed on 2010/12/21 22:54 UTC
Read the original article Hit count: 255

Hello, I'm able to create and send a JSON object like so:

  @mylist << {
    :id => item.id,
    :name => name.id
  }

render :json => { :result => 'success', :mylist => @mylist }

That works great. Problem I'm having now is that I need to include users with are 1 or more per item.

  @mylist << {
    :id => item.id,
    :name => name.id,
    :users => item.users
  }

Where item.users contains a list of (user.id, user.name, user.desc).

how do I include an array like users inside a json object? How to build in Rails and then how to parse it with jQuery?

Thanks

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails3