forked from OpenNeo/impress
sort colors by name on frontpage, in wardrobe
This commit is contained in:
parent
3e1d6aefea
commit
e2d48a67df
3 changed files with 22 additions and 15 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue