fix error

This commit is contained in:
chiu 2020-03-17 09:26:34 +08:00
parent a3a04eee6c
commit d834b63a7f
2 changed files with 6 additions and 7 deletions

View File

@ -4,7 +4,7 @@ class AnnouncementsController < ApplicationController
Bulletin.remove_expired_status Bulletin.remove_expired_status
sorted,total_pages = get_sorted_annc sorted,total_pages = get_sorted_annc
anns = sorted.collect do |a| anns = sorted.collect do |a|
if !a["source-site"].present? if a["source-site"].blank?
statuses = a.statuses_with_classname.collect do |status| statuses = a.statuses_with_classname.collect do |status|
{ {
"status" => status["name"], "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 [] 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 "" author = User.find(a.create_user_id).member_profile.name rescue ""
desc = a.image_description 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) link_to_show = a.is_external_link ? a.external_link : OrbitHelper.url_to_show(a.to_param)
target = a.is_external_link ? "_blank" : "_self" target = a.is_external_link ? "_blank" : "_self"
doc = Nokogiri::HTML(a.title) doc = Nokogiri::HTML(a.title)

View File

@ -101,7 +101,7 @@ module AnnouncementsHelper
fans fans
end end
def filter_by_keywords(sorted,keywords) def filter_by_keywords(sorted,keywords)
if !keywords.nil? if !keywords.to_s.empty?
sorted.select{|anns| sorted.select{|anns|
if anns["source-site"].present? if anns["source-site"].present?
title = Nokogiri::HTML(anns["title"].to_s).text title = Nokogiri::HTML(anns["title"].to_s).text
@ -139,11 +139,10 @@ module AnnouncementsHelper
if announcements.count != 0 if announcements.count != 0
top_anns = announcements.select{|v| v.is_top} top_anns = announcements.select{|v| v.is_top}
rest_all_anns = feeds_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"]} rest_anns = rest_all_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
anns = top_anns + rest_anns all_sorted = top_anns + rest_anns
all_sorted = anns.sort_by{|v| v["postdate"] }
else else
all_sorted = feeds_anns.sort_by{|v| v["postdate"] } all_sorted = feeds_anns.sort{|v1,v2| v2["postdate"]<=>v1["postdate"]}
end end
all_filter = filter_by_keywords(all_sorted,params[:keywords]) all_filter = filter_by_keywords(all_sorted,params[:keywords])
else else