From 743ec4d9104c6ae74766f2d17d772597078e954b Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 20 May 2010 21:30:12 -0400 Subject: [PATCH] restrict item swf assets by fitting body id --- app/controllers/swf_assets_controller.rb | 9 ++++++--- app/models/swf_asset.rb | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/swf_assets_controller.rb b/app/controllers/swf_assets_controller.rb index 9c68677c..65fbc1cd 100644 --- a/app/controllers/swf_assets_controller.rb +++ b/app/controllers/swf_assets_controller.rb @@ -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 diff --git a/app/models/swf_asset.rb b/app/models/swf_asset.rb index 6244a933..5ecb33f1 100644 --- a/app/models/swf_asset.rb +++ b/app/models/swf_asset.rb @@ -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)