Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fetch_weather.rb model
- class FetchWeather < ActiveRecord::Base
- def fetch_weather
- HTTParty.get("http://api.wunderground.com/api/0299ecb9aa94e332/hourly/q/" + "37064" + ".xml")
- end
- attr_accessor :temperature, :condition
- def initialize
- weather_hash = fetch_weather
- assign_values(weather_hash)
- end
- def assign_values(weather_hash)
- hourly_forecast_response = weather_hash.parsed_response['response']['hourly_forecast']['forecast'].first
- self.temperature = hourly_forecast_response['temp']['english']
- self.condition = hourly_forecast_response['condition']
- end
- end
- # weather_controller.rb
- class WeatherController < ApplicationController
- def weather
- @weather_lookup = FetchWeather.new
- end
- end
- # weather view of weather controller (weather#weather)
- <h2>CITY</h2>
- <h3><%= @weather_lookup.temperature %>° - <%= @weather_lookup.condition %></h3>
- <h3><%= params[:zip] %></h3>
- # routes.rb
- Eightbitwx::Application.routes.draw do
- get "weather/weather"
- match ":zip" => "weather#weather"
- root :to => 'pages#home'
- end
Advertisement
Add Comment
Please, Sign In to add comment