From d834b63a7f6f2b2be20b358b064ca5d7be62899c Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 17 Mar 2020 09:26:34 +0800 Subject: [PATCH] fix error --- app/controllers/announcements_controller.rb | 4 ++-- app/helpers/announcements_helper.rb | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 7e390db..21123ff 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -4,7 +4,7 @@ class AnnouncementsController < ApplicationController Bulletin.remove_expired_status sorted,total_pages = get_sorted_annc anns = sorted.collect do |a| - if !a["source-site"].present? + if a["source-site"].blank? statuses = a.statuses_with_classname.collect do |status| { "status" => status["name"], @@ -17,7 +17,7 @@ class AnnouncementsController < ApplicationController links = a.bulletin_links.map{|link| { "link_url" => link.url, "link_title" => (link.title.blank? ? link.url : link.title) } } rescue [] author = User.find(a.create_user_id).member_profile.name rescue "" desc = a.image_description - desc = (desc.nil? || desc == "" ? "announcement image" : desc) + desc = (desc.blank? ? "announcement image" : desc) link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param) target = a.is_external_link ? "_blank" : "_self" doc = Nokogiri::HTML(a.title) diff --git a/app/helpers/announcements_helper.rb b/app/helpers/announcements_helper.rb index 2cfe056..5da2780 100644 --- a/app/helpers/announcements_helper.rb +++ b/app/helpers/announcements_helper.rb @@ -101,7 +101,7 @@ module AnnouncementsHelper fans end def filter_by_keywords(sorted,keywords) - if !keywords.nil? + if !keywords.to_s.empty? sorted.select{|anns| if anns["source-site"].present? title = Nokogiri::HTML(anns["title"].to_s).text @@ -139,11 +139,10 @@ module AnnouncementsHelper if announcements.count != 0 top_anns = announcements.select{|v| v.is_top} rest_all_anns = feeds_anns + announcements.select{|v| !v.is_top} - rest_anns = rest_all_anns.sort_by{|v| v["postdate"]} - anns = top_anns + rest_anns - all_sorted = anns.sort_by{|v| v["postdate"] } + rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} + all_sorted = top_anns + rest_anns else - all_sorted = feeds_anns.sort_by{|v| v["postdate"] } + all_sorted = feeds_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]} end all_filter = filter_by_keywords(all_sorted,params[:keywords]) else