From 054ef9c947a7caad959b42f82bd4199c907b6af0 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Fri, 10 Oct 2014 19:23:38 +0300 Subject: [PATCH] Sort suggestions by speaker name --- app/models/suggestion_group.rb | 2 +- app/models/user.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/suggestion_group.rb b/app/models/suggestion_group.rb index 34666bc..3f35d40 100644 --- a/app/models/suggestion_group.rb +++ b/app/models/suggestion_group.rb @@ -5,7 +5,7 @@ class SuggestionGroup def self.where(conditions = {}) Event.joins(:track).includes(:user).where(conditions).group_by(&:user).map do |speaker, suggestions| SuggestionGroup.new speaker: speaker, suggestions: suggestions - end + end.sort_by { |group| group.speaker.name } end def self.for_conference(conference, conditions = {}) diff --git a/app/models/user.rb b/app/models/user.rb index 0ecaa45..e7cbc1f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -13,6 +13,10 @@ class User < ActiveRecord::Base default_scope { order id: :desc } + def name + speaker_profile.try(:name) || email + end + def toggle_admin! update admin: !admin end