tap/app/controllers/concerns/statistics.rb

25 lines
495 B
Ruby
Raw Normal View History

2015-09-14 20:26:16 +02:00
module Statistics
extend ActiveSupport::Concern
def products_group_by_category
products
.select("products.category", "sum(order_items.count) as count")
.group(:category)
end
def all_orders page
orders
.order(:created_at)
.reverse_order
.paginate(page: page)
end
def products_group_by_id
products
.select("products.*", "sum(order_items.count) as count")
.group(:product_id)
.order("count")
.reverse_order
end
end