From 338d20cfac9c4214dd8c3dd5022283b16ddc7714 Mon Sep 17 00:00:00 2001 From: Jared Cosulich Date: Wed, 18 Oct 2017 12:11:48 -0400 Subject: [PATCH] alphabetic ordering --- app/controllers/districts_controller.rb | 2 +- app/controllers/welcome_controller.rb | 4 ++-- app/models/district.rb | 3 +++ app/views/districts/show.html.haml | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/districts_controller.rb b/app/controllers/districts_controller.rb index 5d3a05b5..3d9129e9 100644 --- a/app/controllers/districts_controller.rb +++ b/app/controllers/districts_controller.rb @@ -4,7 +4,7 @@ class DistrictsController < ApplicationController # GET /districts # GET /districts.json def index - @districts = District.all + @districts = District.all.alphabetic end # GET /districts/1 diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index e9c6739c..b9e5550d 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,8 +1,8 @@ class WelcomeController < ApplicationController def index - @districts = District.all - @schools = School.all + @districts = District.all.alphabetic + @schools = School.all.alphabetic end end diff --git a/app/models/district.rb b/app/models/district.rb index 1b2126aa..bf80d381 100644 --- a/app/models/district.rb +++ b/app/models/district.rb @@ -2,4 +2,7 @@ class District < ApplicationRecord has_many :schools validates :name, presence: true + + scope :alphabetic, -> { order(name: :asc) } + end diff --git a/app/views/districts/show.html.haml b/app/views/districts/show.html.haml index e213627c..35f20e41 100644 --- a/app/views/districts/show.html.haml +++ b/app/views/districts/show.html.haml @@ -12,7 +12,7 @@ = @district.name %br - - @district.schools.each do |school| + - @schools.each do |school| %p= link_to school.name, school %br