jeudi 21 juillet 2016

Retrieve data using for loop in Ruby

I have a question about using foreach loops in ruby. I want to to display documents and I am using a foreach loop in order to display these documents. However, it does give me an error with the "i" variable inside of data["response"]["docs"][i]["topic"] (this is a json string I am iterating over) and I do not understand why that is, can anyone tell me what I am doing wrong? If I simply do data["response"]["docs"][0]["topic"] it works fine but not with the "i" why is that?

<%
(0..10).each do |i|
%>
<%= i %> <br/>
<%= data["response"]["docs"][i]["topic"] %> 
<%
end
%>

Aucun commentaire:

Enregistrer un commentaire