Ruby data structure to render a certain JSON format
Posted
by dt
on Stack Overflow
See other posts from Stack Overflow
or by dt
Published on 2010-04-18T20:48:02Z
Indexed on
2010/04/18
20:53 UTC
Read the original article
Hit count: 458
ruby-on-rails
|JSON
[{"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!
© Stack Overflow or respective owner