fix news count

This commit is contained in:
nccu 2015-01-09 15:23:26 +08:00
parent 9033b2dfa3
commit 7ec60e32bc
1 changed files with 4 additions and 4 deletions

View File

@ -7,13 +7,13 @@ class NewsController < ApplicationController
if params[:keywords] if params[:keywords]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil? news = NewsBulletin.where(:title.ne => "").any_of(:title => /#{params[:keywords].to_s}/i).is_approved.order_by(sort).filter_by_categories(["all"]).per(15) if !params[:keywords].nil?
news_count = news.count news_count = ",共有" + news.count.to_s + "筆資料"
keyword = "搜尋標題有關 ' " + params[:keywords] + " '" keyword = "搜尋標題有關 ' " + params[:keywords] + " '"
elsif params[:department] elsif params[:department]
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil dept = Department.find_by(:uid => params["department"].split("-").last) rescue nil
news = NewsBulletin.where(:title.ne => "" ,:department => dept).is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil? news = NewsBulletin.where(:title.ne => "" ,:department => dept).is_approved.order_by(sort).filter_by_categories(["all"]) if !dept.nil?
news_count = news.count news_count = ",共有" + news.count.to_s + "筆資料"
keywords = params[:department].split("-") keywords = params[:department].split("-")
keywords.delete(keywords.last) keywords.delete(keywords.last)
@ -27,7 +27,7 @@ class NewsController < ApplicationController
unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil unit = Unit.find_by(:uid => params["unit"].split("-").last) rescue nil
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
news = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil? news = NewsBulletin.where(:title.ne => "" ,:unit => unit).is_approved.order_by(sort).filter_by_categories(["all"]) if !unit.nil?
news_count = news.count news_count = ",共有" + news.count.to_s + "筆資料"
keywords = params[:unit].split("-") keywords = params[:unit].split("-")
keywords.delete(keywords.last) keywords.delete(keywords.last)
@ -40,7 +40,7 @@ class NewsController < ApplicationController
!params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"} !params[:sort].blank? ? sort = {params[:sort].to_sym=>params[:order]} : sort = {:is_top=>"desc",:postdate=>"desc"}
category = Category.find_by(:uid => params["category"].split("-").last) rescue nil category = Category.find_by(:uid => params["category"].split("-").last) rescue nil
news = NewsBulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil? news = NewsBulletin.all.where(:title.ne => "").is_approved.order_by(sort).filter_by_categories([category.id.to_s]) if !category.nil?
news_count = news.count news_count = ",共有" + news.count.to_s + "筆資料"
keywords = params[:category].split("-") keywords = params[:category].split("-")
keywords.delete(keywords.last) keywords.delete(keywords.last)