Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def refresh
- json = Rails.cache.fetch('json-all', :expires_in => 1.seconds) do
- json = {}
- json[:server_time] = Time.zone.now.to_i
- items = Item.all :conditions => { :et => { "$gt" => Time.now }}
- json[:items] = {}
- items.each do |item|
- time = (item.et - Time.zone.now)
- hours = (time/3600).to_i
- minutes = (time/60 - hours * 60).to_i
- seconds = (time - (minutes * 60 + hours * 3600))
- json[:items][item.id.to_s.to_sym] = {}
- json[:items][item.id.to_s.to_sym][:price] = item.price.to_f / 100
- json[:items][item.id.to_s.to_sym][:et] = "%02d:%02d:%02d" % [hours, minutes, seconds]
- json[:items][item.id.to_s.to_sym][:bids] = item.bids
- json[:items][item.id.to_s.to_sym][:state] = item.et > Time.now ? "online" : "completed"
- end
- logger.info { ">>> Clear cache" }
- json
- end
- render :json => json.to_json
- end
Add Comment
Please, Sign In to add comment