From 5b88d8373cbd9a47b24cfd54b26367546aab314b Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 19 May 2015 14:57:18 +0800 Subject: [PATCH] fix not nil announcement --- app/controllers/announcements_controller.rb | 7 ++++--- app/models/bulletin.rb | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb index 3bd040b..e264e97 100644 --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -2,9 +2,9 @@ class AnnouncementsController < ApplicationController def index if !OrbitHelper.params['tags'].blank? - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:postdate=>'desc').filter_by_tags(OrbitHelper.params['tags']).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) + announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:title.ne => nil).can_display.is_approved.order_by(:postdate=>'desc').filter_by_tags(OrbitHelper.params['tags']).page(OrbitHelper.page_number).per(OrbitHelper.page_data_count) else - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:postdate=>'desc').filter_by_categories.filter_by_tags + announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:title.ne => nil).can_display.is_approved.order_by(:postdate=>'desc').filter_by_categories.filter_by_tags end anns = announcements.collect do |a| @@ -60,7 +60,8 @@ class AnnouncementsController < ApplicationController end def widget - announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil]).can_display.is_approved.order_by(:postdate=>'desc').filter_by_widget_categories.filter_by_tags(OrbitHelper.widget_tags) + tags = ["all"] if OrbitHelper.widget_tags.empty? + announcements = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil],:title.ne => nil).can_display.is_approved.order_by(:postdate=>'desc').filter_by_widget_categories.filter_by_tags(tags) page = Page.where(:module => "announcement").first rescue nil anns = announcements.collect do |a| statuses = a.statuses_with_classname.collect do |status| diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 8bfd6ac..c097221 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -39,7 +39,7 @@ class Bulletin before_destroy :destroy_email - scope :can_display, ->{where(:is_hidden=>false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])} + scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc])} scope :is_approved, ->{where(:approved => true)} before_create :set_expire