From 1431905f1bd3f667dc234193a0c80caa8dced7a4 Mon Sep 17 00:00:00 2001 From: Akhil Date: Sun, 1 Jun 2014 12:08:11 +0530 Subject: [PATCH] sort --- app/models/helper_model.rb | 2 +- app/models/outcome.rb | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/helper_model.rb b/app/models/helper_model.rb index 188f0c6..48ba0c4 100644 --- a/app/models/helper_model.rb +++ b/app/models/helper_model.rb @@ -3,7 +3,7 @@ module HelperModel def self.get_response user response = {} slack_time = 5.minutes - response['all_events'] = Event.where("open_till > ?", Time.zone.now + slack_time).collect { |event| + response['all_events'] = Event.where("open_till > ?", Time.zone.now + slack_time).order('total_bets desc').collect { |event| { 'id' => event.id, 'name' => event.name, diff --git a/app/models/outcome.rb b/app/models/outcome.rb index 8e38cd7..2d58a0f 100644 --- a/app/models/outcome.rb +++ b/app/models/outcome.rb @@ -3,8 +3,15 @@ class Outcome < ActiveRecord::Base def recalculate_and_update_odds(outcome_id=nil, event_id=nil) # a new bet has been placed on this order - + total_odds = 0 + Event.find(event_id.to_i).outcomes.each do |x| + total_odds += x.odds.to_i + end + Event.find(event_id.to_i).outcomes.each do |x| + x.odds_display_text = x.odds.to_s + ":" + (total_odds-x.odds.to_i).to_s + x.save + end end belongs_to :event