Created
May 14, 2013 00:27
-
-
Save gogogarrett/5572674 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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