Fix query for category in default widget
This commit is contained in:
parent
5a177f34a8
commit
c27141ff5a
|
@ -23,7 +23,7 @@ class DefaultWidgetController< OrbitWidgetController
|
|||
elsif params["category_id"].blank?
|
||||
result = eval(@default_widget["query"])
|
||||
else
|
||||
result = eval("#{ori_class_name}.where(:category_id=>params['category_id'])")
|
||||
result = eval("#{ori_class_name}.where(get_category_field_name(ori_class_name) => params['category_id'])")
|
||||
end
|
||||
result.available_for_lang(I18n.locale).can_display
|
||||
end
|
||||
|
@ -47,15 +47,9 @@ 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
|
||||
<<<<<<< HEAD
|
||||
@data = eval(@default_widget["query"]).includes(@widget_image_field).page(params[:page_main]).per(@data_limit).desc(:created_at)
|
||||
else
|
||||
@data = eval(@default_widget["query"]).limit(@data_limit).includes(@widget_image_field).desc(:created_at)
|
||||
=======
|
||||
@data = query_for_default_widget.includes(@widget_image_field).page(params[:page_main]).per(@data_limit)
|
||||
else
|
||||
@data = query_for_default_widget.limit(@data_limit).includes(@widget_image_field)
|
||||
>>>>>>> 4650f80... default widget query for category and tags
|
||||
end
|
||||
case params[:type]
|
||||
when "typeA"
|
||||
|
@ -71,4 +65,11 @@ class DefaultWidgetController< OrbitWidgetController
|
|||
end
|
||||
end
|
||||
|
||||
def get_category_field_name(ori_class_name)
|
||||
ori_class_name = ori_class_name.constantize
|
||||
ori_class_name.fields.each_key do |key|
|
||||
return key if key.include?('category_id')
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue