restrict item swf assets by fitting body id

This commit is contained in:
Emi Matchu 2010-05-20 21:30:12 -04:00
parent 82c2ff6206
commit 743ec4d910
2 changed files with 7 additions and 3 deletions

View file

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

View file

@ -6,6 +6,7 @@ class SwfAsset < ActiveRecord::Base
delegate :depth, :to => :zone
scope :for_json, includes(:zone)
scope :fitting_body_id, lambda { |body_id| where(arel_table[:body_id].in([body_id, 0])) }
def local_url
uri = URI.parse(url)