I’m getting a really strange error message in my app. In my controller I have:
require 'open-uri'
require 'json'
class NoticiasController < ApplicationController
def index
url = 'https://api.twitter.com/1/trends/daily.json'
buffer = open(url, "UserAgent" => "Ruby-Wget").read
# convert JSON data into a hash
@result = JSON.parse(buffer)
end
end
and in the view I have
<div>
<% for news in @result['trends'] %>
<p><%= news['name'] %></p>
<% end %>
</div>
but I get “TypeError: can’t convert String into Integer”.
What am I doing wrong?
results['trends']is a map of timestamp => [trends].You need to pick a trend date, then iterate over the array of trends.
For example, to get the names of the latest trends: