forked from OpenNeo/impress
move species to database
This commit is contained in:
parent
94ecc6f02d
commit
965465ca51
8 changed files with 50 additions and 29 deletions
|
@ -43,7 +43,7 @@ class OutfitsController < ApplicationController
|
||||||
def new
|
def new
|
||||||
unless localized_fragment_exist?(:action_suffix => 'start_from_scratch_form_content')
|
unless localized_fragment_exist?(:action_suffix => 'start_from_scratch_form_content')
|
||||||
@colors = Color.all_ordered_by_name
|
@colors = Color.all_ordered_by_name
|
||||||
@species = Species.all_ordered_by_name
|
@species = Species.alphabetical
|
||||||
end
|
end
|
||||||
|
|
||||||
unless localized_fragment_exist?('outfits#new newest_items')
|
unless localized_fragment_exist?('outfits#new newest_items')
|
||||||
|
@ -66,8 +66,13 @@ class OutfitsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@species = Species.find_by_name params[:species_name]
|
Globalize.with_locale(I18n.default_locale) do
|
||||||
@color = Color.find_by_name params[:color_name]
|
# Start URLs are always in English, so let's make sure we search in
|
||||||
|
# English.
|
||||||
|
@species = Species.find_by_name params[:species_name]
|
||||||
|
@color = Color.find_by_name params[:color_name]
|
||||||
|
end
|
||||||
|
|
||||||
if @species && @color
|
if @species && @color
|
||||||
redirect_to wardrobe_path(:species => @species.id, :color => @color.id)
|
redirect_to wardrobe_path(:species => @species.id, :color => @color.id)
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
class PetAttributesController < ApplicationController
|
class PetAttributesController < ApplicationController
|
||||||
caches_page :index
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
render :json => {
|
render :json => {
|
||||||
:color => Color.all_ordered_by_name,
|
:color => Color.all_ordered_by_name,
|
||||||
:species => Species.all_ordered_by_name
|
:species => Species.alphabetical
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ module ItemsHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def standard_species_search_links
|
def standard_species_search_links
|
||||||
build_on_pet_types(Species.all) do |pet_type|
|
build_on_pet_types(Species.alphabetical) do |pet_type|
|
||||||
image = pet_type_image(pet_type, :happy, :zoom)
|
image = pet_type_image(pet_type, :happy, :zoom)
|
||||||
query = "species:#{pet_type.species.name}"
|
query = "species:#{pet_type.species.name}"
|
||||||
link_to(image, items_path(:q => query))
|
link_to(image, items_path(:q => query))
|
||||||
|
|
|
@ -193,6 +193,10 @@ class Item < ActiveRecord::Base
|
||||||
species_ids = pet_types.map(&:species_id).uniq
|
species_ids = pet_types.map(&:species_id).uniq
|
||||||
Species.find(species_ids)
|
Species.find(species_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def support_species?(species)
|
||||||
|
species_support_ids.blank? || species_support_ids.include?(species.id)
|
||||||
|
end
|
||||||
|
|
||||||
def as_json(options = {})
|
def as_json(options = {})
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,6 +3,7 @@ class PetType < ActiveRecord::Base
|
||||||
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/1/1\.png$};
|
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/1/1\.png$};
|
||||||
IMAGE_CPN_ACCEPTABLE_NAME = /^[a-z0-9_]+$/
|
IMAGE_CPN_ACCEPTABLE_NAME = /^[a-z0-9_]+$/
|
||||||
|
|
||||||
|
belongs_to :species
|
||||||
has_one :contribution, :as => :contributed
|
has_one :contribution, :as => :contributed
|
||||||
has_many :pet_states
|
has_many :pet_states
|
||||||
has_many :pets
|
has_many :pets
|
||||||
|
@ -65,20 +66,6 @@ class PetType < ActiveRecord::Base
|
||||||
@color ||= Color.find(color_id)
|
@color ||= Color.find(color_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def species_id=(new_species_id)
|
|
||||||
@species = nil
|
|
||||||
write_attribute('species_id', new_species_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def species=(new_species)
|
|
||||||
@species = new_species
|
|
||||||
write_attribute('species_id', @species.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def species
|
|
||||||
@species ||= Species.find(species_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def image_hash
|
def image_hash
|
||||||
self['image_hash'] || basic_image_hash
|
self['image_hash'] || basic_image_hash
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
class Species < PetAttribute
|
class Species < ActiveRecord::Base
|
||||||
fetch_objects!
|
translates :name
|
||||||
|
|
||||||
def self.require_by_name(name)
|
scope :alphabetical, lambda { includes(:translations).order(Species::Translation.arel_table[:name]) }
|
||||||
species = Species.find_by_name(name)
|
|
||||||
raise NotFound, "Species \"#{name.humanize}\" does not exist" unless species
|
def as_json(options={})
|
||||||
species
|
{:id => id, :name => human_name}
|
||||||
end
|
end
|
||||||
|
|
||||||
class NotFound < ArgumentError;end
|
def human_name
|
||||||
|
name.capitalize
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
11
db/migrate/20130121193957_create_species.rb
Normal file
11
db/migrate/20130121193957_create_species.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class CreateSpecies < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :species
|
||||||
|
Species.create_translation_table! :name => :string
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :species
|
||||||
|
Species.drop_translation_table!
|
||||||
|
end
|
||||||
|
end
|
16
db/schema.rb
16
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20130111213346) do
|
ActiveRecord::Schema.define(:version => 20130121193957) do
|
||||||
|
|
||||||
create_table "auth_servers", :force => true do |t|
|
create_table "auth_servers", :force => true do |t|
|
||||||
t.string "short_name", :limit => 10, :null => false
|
t.string "short_name", :limit => 10, :null => false
|
||||||
|
@ -217,6 +217,20 @@ ActiveRecord::Schema.define(:version => 20130111213346) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "species", :force => true do |t|
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "species_translations", :force => true do |t|
|
||||||
|
t.integer "species_id"
|
||||||
|
t.string "locale"
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "species_translations", ["locale"], :name => "index_species_translations_on_locale"
|
||||||
|
add_index "species_translations", ["species_id"], :name => "index_species_translations_on_species_id"
|
||||||
|
|
||||||
create_table "swf_assets", :force => true do |t|
|
create_table "swf_assets", :force => true do |t|
|
||||||
t.string "type", :limit => 7, :null => false
|
t.string "type", :limit => 7, :null => false
|
||||||
t.integer "remote_id", :limit => 3, :null => false
|
t.integer "remote_id", :limit => 3, :null => false
|
||||||
|
|
Loading…
Reference in a new issue