swf asset json for pet types

This commit is contained in:
Emi Matchu 2010-05-20 19:56:08 -04:00
parent d4705e26fa
commit 8411d4c64a
4 changed files with 13 additions and 5 deletions

View file

@ -1,5 +1,10 @@
class SwfAssetsController < ApplicationController class SwfAssetsController < ApplicationController
def index def index
render :json => Item.find(params[:item_id]).swf_assets if params[:item_id]
@swf_assets = Item.find(params[:item_id]).swf_assets.for_json.all
elsif params[:pet_type_id]
@swf_assets = PetType.find(params[:pet_type_id]).swf_assets.for_json.all
end
render :json => @swf_assets
end end
end end

View file

@ -5,6 +5,8 @@ class SwfAsset < ActiveRecord::Base
delegate :depth, :to => :zone delegate :depth, :to => :zone
scope :for_json, includes(:zone)
def local_url def local_url
uri = URI.parse(url) uri = URI.parse(url)
uri.host = RemoteImpressHost uri.host = RemoteImpressHost
@ -13,7 +15,7 @@ class SwfAsset < ActiveRecord::Base
uri.to_s uri.to_s
end end
def as_json def as_json(options={})
{ {
:id => id, :id => id,
:depth => depth, :depth => depth,

View file

@ -1,12 +1,12 @@
module SwfAssetParent module SwfAssetParent
def swf_assets def swf_assets
rels = Table(ParentSwfAssetRelationship.table_name) rels = ParentSwfAssetRelationship.arel_table
type = self.class::SwfAssetType type = self.class::SwfAssetType
ids = ParentSwfAssetRelationship. ids = ParentSwfAssetRelationship.
where(rels[:parent_id].eq(id).and(rels[:swf_asset_type].eq(type))). where(rels[:parent_id].eq(id).and(rels[:swf_asset_type].eq(type))).
select(rels[:swf_asset_id]). select(rels[:swf_asset_id]).
all.map(&:swf_asset_id) all.map(&:swf_asset_id)
assets = Table(SwfAsset.table_name) assets = SwfAsset.arel_table
SwfAsset.where(assets[:id].in(ids)).all SwfAsset.where(assets[:id].in(ids))
end end
end end

View file

@ -3,6 +3,7 @@ OpenneoImpressItems::Application.routes.draw do |map|
match '/:id' => 'items#show', :as => :item match '/:id' => 'items#show', :as => :item
match '/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets match '/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets
match '/pet_types/:pet_type_id/swf_assets.json' => 'swf_assets#index', :as => :pet_type_swf_assets
match '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show' match '/species/:species_id/color/:color_id/pet_type.json' => 'pet_types#show'
end end