added keywords filteration for index pages

This commit is contained in:
Harry Bomrah 2016-04-25 20:10:44 +08:00
parent 2983b2b691
commit e0d0a2aaa6
1 changed files with 12 additions and 0 deletions

View File

@ -20,9 +20,21 @@ class AnnouncementsController < ApplicationController
announcements = announcements.concat(feeds_anns) announcements = announcements.concat(feeds_anns)
sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] } sorted = announcements.sort{ |k,v| v["postdate"] <=> k["postdate"] }
sorted = top_anns + sorted sorted = top_anns + sorted
if params["keywords"].present?
sorted = sorted.find_all{|anns|
if anns["source-site"].present?
/#{params[:keywords].to_s}/i.match anns["title"]
else
/#{params[:keywords].to_s}/i.match anns.title
end
}
end
sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] sorted = Kaminari.paginate_array(sorted).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
else else
announcements = top_anns + announcements announcements = top_anns + announcements
if params["keywords"].present?
announcements = announcements.find_all{|anns| /#{params[:keywords].to_s}/i.match anns.title}
end
sorted = Kaminari.paginate_array(announcements).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue [] sorted = Kaminari.paginate_array(announcements).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) rescue []
end end
total_pages = sorted.total_pages total_pages = sorted.total_pages