Skip to content

Instantly share code, notes, and snippets.

@bomatson
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save bomatson/9f9a64d451685d2f2c9a to your computer and use it in GitHub Desktop.

Select an option

Save bomatson/9f9a64d451685d2f2c9a to your computer and use it in GitHub Desktop.
require 'sinatra'
apps = [ "nachos", "guacamole", "bloomin\' onion", "bread sticks", "garlic knots" ]
entrees = [ "chicken parm\'", "lamb kabob", "veggie fajitas"]
desserts = ["chocolate lava cake", "fruit & cheese plate", "salted caramel pudding"]
drinks = ["water", "hot water"]
# if you wanted to make the image urls work, you would need to restructure the data a little bit.
# we want to get in the habit of each potential course 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
# in our view, it gives us the ability to iterate over each course, then use the image url for each item in an img src tag:
# <img src="#{app_hash['image_url']}"/>
get '/' do
#instead of duplicating the data here, you could assign the arrays above to your instance variables (@apps, @entrees):
# @apps = apps
# @entrees = entrees
# etc..
@apps = [ "nachos", "guacamole", "bloomin\' onion", "bread sticks", "garlic knots" ]
@entrees = [ "chicken parm\'", "lamb kabob", "veggie fajitas"]
@desserts = ["chocolate lava cake", "fruit & cheese plate", "salted caramel pudding"]
@drinks = ["water", "hot water"]
erb :home
end
get '/result' do
@test = 'hello'
# great stuff using params.values here!
@food_order = params.values
erb :result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment