impress/app/controllers/pets_controller.rb

29 lines
773 B
Ruby
Raw Normal View History

2010-10-10 19:18:42 -07:00
class PetsController < ApplicationController
2010-11-05 15:45:05 -07:00
rescue_from Pet::PetNotFound, :with => :pet_not_found
DESTINATIONS = {
'needed_items' => '?',
'root' => '#',
'wardrobe' => '#'
}
def load
raise Pet::PetNotFound unless params[:name]
@pet = Pet.load(params[:name])
@pet.save
2010-11-05 15:45:05 -07:00
destination = params[:destination]
destination = 'root' unless DESTINATIONS[destination]
query_joiner = DESTINATIONS[destination]
path = send("#{destination}_path") + query_joiner + @pet.wardrobe_query
redirect_to path
end
protected
def pet_not_found
path = params[:origin] || root_path
path += "?name=#{params[:name]}"
redirect_to path, :alert => 'Could not find any pet by that name. Did you spell it correctly?'
end
end