rails and ruby

About Me

Subscribe now!Feeds RSS

Latest posts

Hot posts

My Bookmarks

Links

I miei progetti

Search

Yahoo Weather API

0 comments

Che tempo fa a Roma oggi?
Per saperlo possiamo sfruttare le Wheather api di Yahoo nella nostra applicazione web fatta con rubyOnRails.

Ecco il metodo del controller:

def index
require 'rexml/document'
url = 'http://weather.yahooapis.com/forecastrss?p=ITXX0067&u=c'

xml = REXML::Document.new Net::HTTP.get(URI.parse(url))
xml.elements.each '//item' do |item|
@item = {
:description => item.elements['description'].text
}
end
end

E nella pagina...

<%= @item%>


Il risultato è questo:

Comments
0 comments
Do you have any suggestions? Add your comment. Please don't spam!
Subscribe to my feed

Posta un commento