Skip to content

Instantly share code, notes, and snippets.

@gogogarrett
Created May 14, 2013 00:27
Show Gist options
  • Select an option

  • Save gogogarrett/5572674 to your computer and use it in GitHub Desktop.

Select an option

Save gogogarrett/5572674 to your computer and use it in GitHub Desktop.
class PurchasesController < ApplicationController
def create
purchase_service = service_lookup[params[:purchase_type]]
item_class = item_class_lookup[params[:purchase_type]]
item = item_class.find_by(name: params[:item_name])
purchase_service.new(current_student, item).purchase
redirect_to map_path
end
private
def service_lookup
{
trip: Purchase::Trip,
souvenir: Purchase::Souvenir
}.with_indifferent_access
end
def item_class_lookup
{
trip: Location,
souvenir: Souvenir
}.with_indifferent_access
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment