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
|
||||
unless localized_fragment_exist?(:action_suffix => 'start_from_scratch_form_content')
|
||||
@colors = Color.all_ordered_by_name
|
||||
@species = Species.all_ordered_by_name
|
||||
@species = Species.alphabetical
|
||||
end
|
||||
|
||||
unless localized_fragment_exist?('outfits#new newest_items')
|
||||
|
@ -66,8 +66,13 @@ class OutfitsController < ApplicationController
|
|||
end
|
||||
|
||||
def start
|
||||
Globalize.with_locale(I18n.default_locale) do
|
||||
# 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
|
||||
redirect_to wardrobe_path(:species => @species.id, :color => @color.id)
|
||||
else
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
class PetAttributesController < ApplicationController
|
||||
caches_page :index
|
||||
|
||||
def index
|
||||
render :json => {
|
||||
:color => Color.all_ordered_by_name,
|
||||
:species => Species.all_ordered_by_name
|
||||
:species => Species.alphabetical
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ module ItemsHelper
|
|||
end
|
||||
|
||||
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)
|
||||
query = "species:#{pet_type.species.name}"
|
||||
link_to(image, items_path(:q => query))
|
||||
|
|
|
@ -194,6 +194,10 @@ class Item < ActiveRecord::Base
|
|||
Species.find(species_ids)
|
||||
end
|
||||
|
||||
def support_species?(species)
|
||||
species_support_ids.blank? || species_support_ids.include?(species.id)
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
{
|
||||
:description => description,
|
||||
|
|
|
@ -3,6 +3,7 @@ class PetType < ActiveRecord::Base
|
|||
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/1/1\.png$};
|
||||
IMAGE_CPN_ACCEPTABLE_NAME = /^[a-z0-9_]+$/
|
||||
|
||||
belongs_to :species
|
||||
has_one :contribution, :as => :contributed
|
||||
has_many :pet_states
|
||||
has_many :pets
|
||||
|
@ -65,20 +66,6 @@ class PetType < ActiveRecord::Base
|
|||
@color ||= Color.find(color_id)
|
||||
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
|
||||
self['image_hash'] || basic_image_hash
|
||||
end
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
class Species < PetAttribute
|
||||
fetch_objects!
|
||||
class Species < ActiveRecord::Base
|
||||
translates :name
|
||||
|
||||
def self.require_by_name(name)
|
||||
species = Species.find_by_name(name)
|
||||
raise NotFound, "Species \"#{name.humanize}\" does not exist" unless species
|
||||
species
|
||||
scope :alphabetical, lambda { includes(:translations).order(Species::Translation.arel_table[:name]) }
|
||||
|
||||
def as_json(options={})
|
||||
{:id => id, :name => human_name}
|
||||
end
|
||||
|
||||
class NotFound < ArgumentError;end
|
||||
def human_name
|
||||
name.capitalize
|
||||
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.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20130111213346) do
|
||||
ActiveRecord::Schema.define(:version => 20130121193957) do
|
||||
|
||||
create_table "auth_servers", :force => true do |t|
|
||||
t.string "short_name", :limit => 10, :null => false
|
||||
|
@ -217,6 +217,20 @@ ActiveRecord::Schema.define(:version => 20130111213346) do
|
|||
t.datetime "updated_at"
|
||||
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|
|
||||
t.string "type", :limit => 7, :null => false
|
||||
t.integer "remote_id", :limit => 3, :null => false
|
||||
|
|
Loading…
Reference in a new issue