I have following code in application controller:
class ApplicationController < ActionController::Base
before_filter :find_today_forecast
...
def find_today_forecast
@today_forecast = Weather.displayed.city(@city).first
end
end
variable @today_forecast updates only when I am restarting application on production and development environment.
Rails.cache.clear and rake tmp:clear doesn't work. What is the problem
Update, Weather models and YandexWeather parser:
class Weather < ActiveRecord::Base
DISPLAY_COUNT = 7
belongs_to :city
scope :city, lambda {|field| {:conditions => {:city_id => field}}}
validates_presence_of :temp_high, :temp_low
validates_uniqueness_of :date, :scope => :city_id
scope :displayed, :conditions => ['date >= ?', Date.today], :order => 'date ASC', :limit => Weather::DISPLAY_COUNT
def high
self.temp_high.to_i > 0 ? '+' + self.temp_high.to_s : self.temp_high
end
def low
self.temp_low.to_i > 0 ? '+' + self.temp_low.to_s : self.temp_low
end
# загружаем погоду из Яндекса
def self.load(city)
begin
YandexWeather.new(city).create_weathers
rescue
Rails.logger.info "no weather for city - #{city.title}"
end
end
end
class YandexWeather
ICON_NAMES = {
'ovc_ra' => 'heavy-rain',
'ovc_-ra' => 'heavy-rain',
'bkn_na' => 'heavy-cloud-day',
'skc_n' => 'sun',
'skc_d' => 'night',
'ovc' => 'heavy-cloud-day',
'bkn_-ra_n' => 'heavy-rain',
'bkn_d' => 'medium-cloud',
'bkn_n' => 'medium-cloud-night',
'bkn_-ra_d' => 'rain',
'ovc_-sn' => 'snow',
'ovc_ts_ra' => 'heavy-storm',
'bkn_-sn_n' => 'snow',
'ovc_sn' => 'snow',
'bkn_-sn_d' => 'chance_of_snow',
'bkn_ra_d' => 'rain',
'bkn_ra_n' => 'rain'
}
PER_PAGE = 10
def initialize city
@agent = Mechanize.new
@city = city
end
...
end