diff --git a/app/controllers/outfits_controller.rb b/app/controllers/outfits_controller.rb index a4f76275..7fd2ca20 100644 --- a/app/controllers/outfits_controller.rb +++ b/app/controllers/outfits_controller.rb @@ -29,8 +29,8 @@ class OutfitsController < ApplicationController end def new - @colors = Color.all - @species = Species.all + @colors = Color.all_ordered_by_name + @species = Species.all_ordered_by_name @top_contributors = User.top_contributors.limit(3) end diff --git a/app/controllers/pet_attributes_controller.rb b/app/controllers/pet_attributes_controller.rb index 6b6ba936..4b3553e6 100644 --- a/app/controllers/pet_attributes_controller.rb +++ b/app/controllers/pet_attributes_controller.rb @@ -1,8 +1,8 @@ class PetAttributesController < ApplicationController def index render :json => { - :color => Color.all, - :species => Species.all + :color => Color.all_ordered_by_name, + :species => Species.all_ordered_by_name } end end diff --git a/app/models/pet_attribute.rb b/app/models/pet_attribute.rb index 4da5523d..ba6285c7 100644 --- a/app/models/pet_attribute.rb +++ b/app/models/pet_attribute.rb @@ -10,18 +10,24 @@ class PetAttribute < StaticResource self.name.capitalize end - def self.find(id) - attribute = super - unless attribute - attribute = new - attribute.id = id - attribute.name = "color \##{id}" + class << self + def all_ordered_by_name + @objects_ordered_by_name + end + + def find(id) + attribute = super + unless attribute + attribute = new + attribute.id = id + attribute.name = "color \##{id}" + end + attribute + end + + def find_by_name(name) + @objects_by_name[name.downcase] end - attribute - end - - def self.find_by_name(name) - @objects_by_name[name.downcase] end private @@ -43,5 +49,6 @@ class PetAttribute < StaticResource File.open(Rails.root.join('config', data_source)).each do |line| process_line(line) end + @objects_ordered_by_name = @objects.sort { |a,b| a.name <=> b.name } end end