Last active
August 29, 2015 14:04
-
-
Save bomatson/e8ebc204bb9bceafcf29 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' | |
require 'httparty' | |
response = HTTParty.get('http://worldcup.sfg.io/matches/') | |
array = response.parsed_response | |
@matches = array | |
# @home_country= ['home_team']['country'] | |
# @away_country= ['away_team']['country'] | |
# ^^^^ we won't want to define our instance variables here, they should be within the 'get' block below: | |
get '/' do | |
#this gives us access to @matches in our view (which you loop through correctly in the view) | |
@matches = array | |
erb :home | |
end | |
post '/search' do | |
# great use of params! | |
@search = params['search'] | |
# erb :search | |
# ^^^ should be the last thing we do | |
# (we don't want to display the view until the end of this method) | |
# we want to check if the @search is equal to our home country. | |
# if it is, let's add the match to an array (since there could be more than one result) | |
# In order to do this, we need to check the home team of each match | |
# try something like this: | |
# set up your results array: | |
# @results = [] | |
# loop through all your matches to find the one that equals the user's search | |
#array.each do |match| | |
# if @search == match['home_country'] | |
# @results << match | |
# end | |
#end | |
#what you'll end up with is an array (@results) that contains matching search results | |
# then this part is not necessary: | |
if @search = @home_country | |
"<%=@home_country%> Vs. <%=@away_country%>" | |
elsif @search = @away_country | |
end | |
#finish by displaying the view with @results | |
erb :search | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment