Election results in the London Borough of Sutton.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

53 wiersze
1.0 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. %body
  25. #main
  26. %h1 Find My Candidates
  27. = yield
  28. #footer
  29. %hr/
  30. %p Design by Adrian Short
  31. @@home
  32. %form{ :method => 'get', :action => '/wards' }
  33. %label{ :for => "postcode" }
  34. Postcode
  35. %input{ :type => 'text', :name => 'postcode', :size => 10 }
  36. %input{ :type => 'submit', :value => "Find" }
  37. - for ward in @wards
  38. %p= ward
  39. @@wards
  40. %h2
  41. #{@ward_name} Ward in #{@district_name}
  42. %p
  43. Your postcode is #{@postcode}