Last active
August 29, 2015 14:04
-
-
Save bomatson/c4ab7611fd94482d124a 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
| require 'sinatra' | |
| MENU = { | |
| # what happens if your appetizers have more than just an image and name? how about if there's a phone number? | |
| # we want to get in the habit of each appetizer being its own object, with properties you can access | |
| # an array of hashes is perfect for our current use case: | |
| # appetizers = [ | |
| # {'name' => 'fries', 'image_url' => 'http://frenzyofnoise.net/wp-content/uploads/2014/05/French-fries-deliciouse.jpg' }, ... | |
| # ] | |
| # then we can access the appetizer properties in an each block: | |
| # appetizers.each do |app_hash| | |
| # puts app_hash['name'] | |
| # puts app_hash['image_url'] | |
| # end | |
| 'appetizers' => [ | |
| {'http://frenzyofnoise.net/wp-content/uploads/2014/05/French-fries-deliciouse.jpg' => 'fries'}, | |
| {'http://whatsgabycooking.com/wp-content/uploads/Loaded-Nachos.jpg' => 'nachos'}, | |
| {'http://foodnetwork.sndimg.com/content/dam/images/food/fullset/2009/11/4/3/FNM_120109-Copy-That-003_s4x3.jpg.rend.sni12col.landscape.jpeg' => 'bloomin onion'} | |
| ], | |
| 'entrees' => ['pizza', 'surf n turf', 'noodles', 'ribs'], | |
| 'desserts' => ['chocolate cake', 'creme brulee', 'ice cream'], | |
| 'drinks' => ['hot chocolate', 'water', 'coke', 'beer'] | |
| } | |
| get "/" do | |
| erb :hone | |
| end | |
| post "/order" do | |
| #typically, we dont want to expose our params directly in the view | |
| # we want to use an instance variable to store the data we need from params | |
| # in this case, the entire params hash is our order: | |
| # @order = params | |
| # then in your view, you can iterate over @order like you did with params | |
| # params.each do |key, value| | |
| # (params[key] ||= []).push(params[value]) | |
| # end | |
| erb :order | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment