forked from OpenNeo/impress
quick pets controller to redirect to wardrobe
This commit is contained in:
parent
16629926fb
commit
33711f6fc6
3 changed files with 26 additions and 1 deletions
7
app/controllers/pets_controller.rb
Normal file
7
app/controllers/pets_controller.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class PetsController < ActionController::Base
|
||||
def show
|
||||
@pet = Pet.load(params[:id])
|
||||
@pet.save
|
||||
redirect_to @pet.wardrobe_url
|
||||
end
|
||||
end
|
|
@ -3,10 +3,11 @@ class Pet < ActiveRecord::Base
|
|||
AMF_SERVICE_NAME = 'CustomPetService'
|
||||
PET_VIEWER_METHOD = 'getViewerData'
|
||||
PET_NOT_FOUND_REMOTE_ERROR = 'PHP: Unable to retrieve records from the database.'
|
||||
WARDROBE_PATH = '/wardrobe'
|
||||
|
||||
belongs_to :pet_type
|
||||
|
||||
attr_reader :items
|
||||
attr_reader :items, :pet_state
|
||||
|
||||
def load!
|
||||
require 'ostruct'
|
||||
|
@ -34,6 +35,21 @@ class Pet < ActiveRecord::Base
|
|||
true
|
||||
end
|
||||
|
||||
def wardrobe_url
|
||||
uri = URI::HTTP.build({
|
||||
:host => RemoteImpressHost,
|
||||
:path => WARDROBE_PATH,
|
||||
:fragment => {
|
||||
:name => self.name,
|
||||
:color => self.pet_type.color.id,
|
||||
:species => self.pet_type.species.id,
|
||||
:state => self.pet_state.id,
|
||||
:objects => self.items.map(&:id)
|
||||
}.to_query
|
||||
})
|
||||
uri.to_s
|
||||
end
|
||||
|
||||
def before_save
|
||||
self.pet_type.save
|
||||
self.items.each(&:save)
|
||||
|
|
|
@ -9,5 +9,7 @@ OpenneoImpressItems::Application.routes.draw do |map|
|
|||
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'
|
||||
|
||||
resources :pets, :only => [:show]
|
||||
|
||||
match '/:id' => 'items#show', :as => :item
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue