sort colors by name on frontpage, in wardrobe

This commit is contained in:
Emi Matchu 2010-11-24 21:17:24 -05:00
parent 3e1d6aefea
commit e2d48a67df
3 changed files with 22 additions and 15 deletions

View file

@ -29,8 +29,8 @@ class OutfitsController < ApplicationController
end end
def new def new
@colors = Color.all @colors = Color.all_ordered_by_name
@species = Species.all @species = Species.all_ordered_by_name
@top_contributors = User.top_contributors.limit(3) @top_contributors = User.top_contributors.limit(3)
end end

View file

@ -1,8 +1,8 @@
class PetAttributesController < ApplicationController class PetAttributesController < ApplicationController
def index def index
render :json => { render :json => {
:color => Color.all, :color => Color.all_ordered_by_name,
:species => Species.all :species => Species.all_ordered_by_name
} }
end end
end end

View file

@ -10,7 +10,12 @@ class PetAttribute < StaticResource
self.name.capitalize self.name.capitalize
end end
def self.find(id) class << self
def all_ordered_by_name
@objects_ordered_by_name
end
def find(id)
attribute = super attribute = super
unless attribute unless attribute
attribute = new attribute = new
@ -20,9 +25,10 @@ class PetAttribute < StaticResource
attribute attribute
end end
def self.find_by_name(name) def find_by_name(name)
@objects_by_name[name.downcase] @objects_by_name[name.downcase]
end end
end
private private
@ -43,5 +49,6 @@ class PetAttribute < StaticResource
File.open(Rails.root.join('config', data_source)).each do |line| File.open(Rails.root.join('config', data_source)).each do |line|
process_line(line) process_line(line)
end end
@objects_ordered_by_name = @objects.sort { |a,b| a.name <=> b.name }
end end
end end