From e2f03069d0d19185d641f9cce3ca29a6f4111044 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 4 Mar 2020 18:39:21 +0800 Subject: [PATCH] fix sorting error --- app/controllers/announcements_controller.rb | 2 +- lib/announcement/engine.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index ea083f7..d6355c5 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -147,7 +147,7 @@ class AnnouncementsController < ApplicationController else feeds_anns = get_feed_announcements("widget") rest_all_anns = feeds_anns + sorted_anns.select{|v| !v.is_top}.take(rest_count).map{|v| data_to_human_type(v)} - rest_anns = rest_all_anns.sort_by{|v| v["postdate"]}.take(rest_count) + rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}.take(rest_count) anns = top_anns + rest_anns end end diff --git a/lib/announcement/engine.rb b/lib/announcement/engine.rb index 8daa015..bb956fa 100644 --- a/lib/announcement/engine.rb +++ b/lib/announcement/engine.rb @@ -35,6 +35,10 @@ module Announcement data[key1] = [value1,value2,value3] data_item[key_item1] = [value_item1,value_item2,value_item3] data_item[key_item2] = [value2_item1,value2_item2] + require File.expand_path('../../../app/models/anns_cache', __FILE__) + if defined? AnnsCache + AnnsCache.all.destroy + end rescue => e puts ['error in announcement',e] end