From e0a4959dc95cb5711f97a6bd63f94e8bf0a793b0 Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Wed, 16 Apr 2014 15:41:11 +0530 Subject: [PATCH] Sort featured badges by badge type first, followed by grant count. --- app/models/user.rb | 4 ++++ app/serializers/user_serializer.rb | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 23f3daa09d3..de6db4cc337 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -492,6 +492,10 @@ class User < ActiveRecord::Base Summarize.new(bio_cooked).summary end + def featured_user_badges + user_badges.joins(:badge).order('badges.badge_type_id ASC, badges.grant_count ASC').includes(:granted_by, badge: :badge_type).limit(3) + end + def self.count_by_signup_date(sinceDaysAgo=30) where('created_at > ?', sinceDaysAgo.days.ago).group('date(created_at)').order('date(created_at)').count end diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb index 1431ccd9f8b..df35418f94e 100644 --- a/app/serializers/user_serializer.rb +++ b/app/serializers/user_serializer.rb @@ -134,9 +134,4 @@ class UserSerializer < BasicUserSerializer def badge_count object.user_badges.count end - - def featured_user_badges - # The three rarest badges this user has received should be featured. - object.user_badges.joins(:badge).order('badges.grant_count ASC').includes(:granted_by, badge: :badge_type).limit(3) - end end