Election results in the London Borough of Sutton.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

54 řádky
1.1 KiB

  1. require 'rubygems'
  2. require 'sinatra'
  3. require 'json'
  4. require 'rest_client'
  5. get '/' do
  6. @wards = %w{ Cheam Sutton Stonecot }
  7. haml :home
  8. end
  9. get '/wards' do
  10. @postcode = params[:postcode].strip.upcase
  11. url = "http://www.uk-postcodes.com/postcode/" + @postcode.gsub(/ /, '') + '.json'
  12. result = RestClient.get(url)
  13. result_ary = JSON.parse(result)
  14. @district_name = result_ary['administrative']['district']['title']
  15. @ward_name = result_ary['administrative']['ward']['title']
  16. haml :wards
  17. end
  18. __END__
  19. @@layout
  20. !!!
  21. %html
  22. %head
  23. %title Find My Candidates
  24. %link{ :rel => 'stylesheet', :type => 'text/css', :href => 'style.css' }
  25. %body
  26. #main
  27. %h1 Find My Candidates
  28. = yield
  29. #footer
  30. %hr/
  31. %p Design by Adrian Short
  32. @@home
  33. %form{ :method => 'get', :action => '/wards' }
  34. %label{ :for => "postcode" }
  35. Postcode
  36. %input{ :type => 'text', :name => 'postcode', :size => 10 }
  37. %input{ :type => 'submit', :value => "Find" }
  38. - for ward in @wards
  39. %p= ward
  40. @@wards
  41. %h2
  42. #{@ward_name} Ward in #{@district_name}
  43. %p
  44. Your postcode is #{@postcode}