From d01968dcd0fb475d0f2766dc587b80e0ca5a00f0 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 21 Mar 2013 02:29:56 +0800 Subject: [PATCH] Changes in query for default widget --- app/controllers/default_widget_controller.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index dd9df0ee..8983084a 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -31,13 +31,12 @@ class DefaultWidgetController< OrbitWidgetController end result = eval("#{ori_class_name}.where(:id=>result_ids)") elsif params["category_id"].blank? #no tag no cate - - result = eval(@default_widget["query"]) - else #no tag has cate - result = eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id'])") + result = eval(@default_widget["query"]) + else #no tag has cate + result = eval("#{ori_class_name}.where(:#{get_category_field_name(ori_class_name)}.in=>params['category_id'])") end date_now = Time.now - result.available_for_lang(I18n.locale).can_display.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:created_at) + result.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) end def default_widget @@ -58,10 +57,10 @@ class DefaultWidgetController< OrbitWidgetController @data_limit = @page_part.widget_data_count.is_a?(Fixnum) ? @page_part.widget_data_count : (@page_part.widget_data_count.to_i rescue 3) end if @paginate - @data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at) + @data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit) # @data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field) else - @data = query_for_default_widget.includes(@widget_image_field).desc(:created_at) + @data = query_for_default_widget.includes(@widget_image_field).limit(@data_limit) # @data = eval(@default_widget["query"]).limit(@data_limit).includes(@widget_image_field).desc(:created_at) end case params[:type]