Fix can_display

This commit is contained in:
chris 2012-08-16 18:55:34 +08:00
parent 3c283d1a7a
commit edf9d8a159
4 changed files with 6 additions and 6 deletions

View File

@ -30,7 +30,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
date_now = Time.now date_now = Time.now
if !params[:category_id].blank? && !params[:tag_id].blank? if !params[:category_id].blank? && !params[:tag_id].blank?
@tag = AnnouncementTag.find(params[:tag_id]) rescue nil @tag = AnnouncementTag.find(params[:tag_id]) rescue nil
@tag = AnnouncementTag.where(id: params[:tag_id])[0] unless @tag @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag
@bulletins = @tag.bulletins.available_for_lang(I18n.locale).can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) @bulletins = @tag.bulletins.available_for_lang(I18n.locale).can_display.where(:bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15)
@current_category = BulletinCategory.from_id(params[:category_id]) rescue nil @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil
elsif !params[:category_id].blank? elsif !params[:category_id].blank?
@ -38,7 +38,7 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
@current_category = BulletinCategory.from_id(params[:category_id]) rescue nil @current_category = BulletinCategory.from_id(params[:category_id]) rescue nil
elsif !params[:tag_id].blank? elsif !params[:tag_id].blank?
@tag = AnnouncementTag.find(params[:tag_id]) rescue nil @tag = AnnouncementTag.find(params[:tag_id]) rescue nil
@tag = AnnouncementTag.where(id: params[:tag_id])[0] unless @tag @tag = AnnouncementTag.where(key: params[:tag_id])[0] unless @tag
@bulletins = @tag.bulletins.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) @bulletins = @tag.bulletins.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15)
else else
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15)

View File

@ -43,7 +43,7 @@ class Bulletin
field :public, :type => Boolean, :default => true field :public, :type => Boolean, :default => true
scope :can_display,all_of(is_checked: true,is_rejected: false,is_pending: false) scope :can_display, where(is_checked: true, is_rejected: false, is_pending: false)
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) } scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
mount_uploader :image, ImageUploader mount_uploader :image, ImageUploader

View File

@ -31,7 +31,7 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
date_now = Time.now date_now = Time.now
if !params[:category_id].blank? && !params[:tag_id].blank? if !params[:category_id].blank? && !params[:tag_id].blank?
@tag = NewsTag.find(params[:tag_id]) rescue nil @tag = NewsTag.find(params[:tag_id]) rescue nil
@tag = NewsTag.where(id: params[:tag_id])[0] unless @tag @tag = NewsTag.where(key: params[:tag_id])[0] unless @tag
@news_bulletins = @tag.news_bulletins.available_for_lang(I18n.locale).can_display.where(:news_bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) @news_bulletins = @tag.news_bulletins.available_for_lang(I18n.locale).can_display.where(:news_bulletin_category_id => params[:category_id]).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15)
@current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil @current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil
elsif !params[:category_id].blank? elsif !params[:category_id].blank?
@ -39,7 +39,7 @@ class Panel::News::FrontEnd::NewsBulletinsController < OrbitWidgetController
@current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil @current_category = NewsBulletinCategory.from_id(params[:category_id]) rescue nil
elsif !params[:tag_id].blank? elsif !params[:tag_id].blank?
@tag = NewsTag.find(params[:tag_id]) rescue nil @tag = NewsTag.find(params[:tag_id]) rescue nil
@tag = NewsTag.where(id: params[:tag_id])[0] unless @tag @tag = NewsTag.where(key: params[:tag_id])[0] unless @tag
@news_bulletins = @tag.news_bulletins.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) @news_bulletins = @tag.news_bulletins.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15)
else else
@news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15) @news_bulletins = NewsBulletin.all.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page_main]).per(15)

View File

@ -43,7 +43,7 @@ class NewsBulletin
field :public, :type => Boolean, :default => true field :public, :type => Boolean, :default => true
scope :can_display,all_of(is_checked: true,is_rejected: false,is_pending: false) scope :can_display, where(is_checked: true, is_rejected: false, is_pending: false)
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) } scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
mount_uploader :image, ImageUploader mount_uploader :image, ImageUploader