Rails - JSON object with an array?
- by AnApprentice
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