Ruby data structure to render a certain JSON format
- by dt
[{"id":"123","name":"House"},
{"id":"1456","name":"Desperate Housewives"},
{"id":"789","name":"Dollhouse"},
{"id":"10","name":"Full House"}
]
How can I render to produce this JSON format from within Ruby? I have all the data from the DB (@result) and don't know what data structure to use in Ruby that will render to this when I do this:
respond_to do |format|
format.json { render :json = @result}
end
What data structure should @result be and how can I iterate to produce it? Thank you!