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
|
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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
end
|
||||||
attribute.id = id
|
|
||||||
attribute.name = "color \##{id}"
|
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
|
end
|
||||||
attribute
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.find_by_name(name)
|
|
||||||
@objects_by_name[name.downcase]
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue