small fix for sorting

This commit is contained in:
Harry Bomrah 2015-08-17 17:49:04 +08:00
parent 88c66108b1
commit 5f17089115
1 changed files with 3 additions and 3 deletions

View File

@ -205,13 +205,13 @@ class NewsController < ApplicationController
link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/" link = page.nil? ? "#" : "/#{I18n.locale.to_s + page.url}/"
categories_for_dropdown.unshift({"name" => t("news.all"), "category-link" => link}) categories_for_dropdown.unshift({"name" => t("news.all"), "category-link" => link})
hot_news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :category_id.in => categories.collect{|cat| cat.id}, :is_hot => true).can_display.is_approved.desc(:created_at).limit(1) hot_news = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :category_id.in => categories.collect{|cat| cat.id}, :is_hot => true).can_display.is_approved.desc(:postdate).limit(1)
hot_news = hot_news.first hot_news = hot_news.first
categories.each_with_index do |category,index| categories.each_with_index do |category,index|
if hot_news.nil? if hot_news.nil?
nbs = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:created_at).limit(OrbitHelper.widget_data_count) nbs = NewsBulletin.where(:title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:postdate).limit(OrbitHelper.widget_data_count)
else else
nbs = NewsBulletin.where(:id.ne => hot_news.id, :title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:created_at).limit(OrbitHelper.widget_data_count) nbs = NewsBulletin.where(:id.ne => hot_news.id, :title.ne => "",:is_preview.in=>[false,nil], :category_id => category.id).can_display.is_approved.desc(:postdate).limit(OrbitHelper.widget_data_count)
end end
temp = nbs.collect do |nb| temp = nbs.collect do |nb|
{ {