1
0
Fork 0
forked from OpenNeo/impress

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,18 +10,24 @@ class PetAttribute < StaticResource
self.name.capitalize self.name.capitalize
end end
def self.find(id) class << self
attribute = super def all_ordered_by_name
unless attribute @objects_ordered_by_name
attribute = new
attribute.id = id
attribute.name = "color \##{id}"
end end
attribute
end
def self.find_by_name(name) def find(id)
@objects_by_name[name.downcase] 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
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