From 3db48c44f76cec9b029fd388eaf17a8e05ea3b15 Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Thu, 30 Jan 2020 13:42:02 +0100 Subject: [PATCH] Add ordered scope --- app/controllers/global_activities_controller.rb | 2 +- app/models/team.rb | 1 + app/views/shared/_navigation.html.erb | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/global_activities_controller.rb b/app/controllers/global_activities_controller.rb index dd83dde77..a52d40e2a 100644 --- a/app/controllers/global_activities_controller.rb +++ b/app/controllers/global_activities_controller.rb @@ -69,7 +69,7 @@ class GlobalActivitiesController < ApplicationController end def team_filter - render json: current_user.teams.order('LOWER(name)').global_activity_filter(activity_filters, params[:query]) + render json: current_user.teams.ordered.global_activity_filter(activity_filters, params[:query]) end def user_filter diff --git a/app/models/team.rb b/app/models/team.rb index 03e0c8fe5..da0b661a4 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -12,6 +12,7 @@ class Team < ApplicationRecord after_create :generate_template_project scope :teams_select, -> { select(:id, :name).order(name: :asc) } + scope :ordered, -> { order('LOWER(name)') } auto_strip_attributes :name, :description, nullify: false validates :name, diff --git a/app/views/shared/_navigation.html.erb b/app/views/shared/_navigation.html.erb index fc3483136..b7ba89280 100644 --- a/app/views/shared/_navigation.html.erb +++ b/app/views/shared/_navigation.html.erb @@ -73,7 +73,7 @@ <%= hidden_field(:user, :current_team_id) %>
- <% current_user.teams.order('LOWER(name)').each do |team| %> + <% current_user.teams.ordered.each do |team| %>
  • <%= link_to Constants::ACADEMY_TR_LINK, - class: "academy-link flag", - title: I18n.t('nav.academy_tooltip'), - target: :_blank do + class: "academy-link flag", + title: I18n.t('nav.academy_tooltip'), + target: :_blank do %>