forked from OpenNeo/impress
swf asset json for pet types
This commit is contained in:
parent
d4705e26fa
commit
8411d4c64a
4 changed files with 13 additions and 5 deletions
|
@ -1,5 +1,10 @@
|
|||
class SwfAssetsController < ApplicationController
|
||||
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
|
||||
|
|
|
@ -5,6 +5,8 @@ class SwfAsset < ActiveRecord::Base
|
|||
|
||||
delegate :depth, :to => :zone
|
||||
|
||||
scope :for_json, includes(:zone)
|
||||
|
||||
def local_url
|
||||
uri = URI.parse(url)
|
||||
uri.host = RemoteImpressHost
|
||||
|
@ -13,7 +15,7 @@ class SwfAsset < ActiveRecord::Base
|
|||
uri.to_s
|
||||
end
|
||||
|
||||
def as_json
|
||||
def as_json(options={})
|
||||
{
|
||||
:id => id,
|
||||
:depth => depth,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
module SwfAssetParent
|
||||
def swf_assets
|
||||
rels = Table(ParentSwfAssetRelationship.table_name)
|
||||
rels = ParentSwfAssetRelationship.arel_table
|
||||
type = self.class::SwfAssetType
|
||||
ids = ParentSwfAssetRelationship.
|
||||
where(rels[:parent_id].eq(id).and(rels[:swf_asset_type].eq(type))).
|
||||
select(rels[:swf_asset_id]).
|
||||
all.map(&:swf_asset_id)
|
||||
assets = Table(SwfAsset.table_name)
|
||||
SwfAsset.where(assets[:id].in(ids)).all
|
||||
assets = SwfAsset.arel_table
|
||||
SwfAsset.where(assets[:id].in(ids))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ OpenneoImpressItems::Application.routes.draw do |map|
|
|||
match '/:id' => 'items#show', :as => :item
|
||||
|
||||
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'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue