Election results in the London Borough of Sutton.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

83 lines
1.6 KiB

  1. require 'rubygems'
  2. require 'sinatra'
  3. require 'sinatra-helpers/haml/partials'
  4. require 'haml'
  5. require 'lib/models'
  6. get '/' do
  7. if params[:postcode]
  8. @postcode = params[:postcode].strip.upcase
  9. unless result = Postcode.finder(@postcode)
  10. # Invalid postcode
  11. redirect '/error'
  12. end
  13. # Postcode valid but not in LB Sutton
  14. if result.district_code != "00BF"
  15. redirect '/aliens'
  16. end
  17. # Postcode in LB Sutton
  18. @ward = Ward.first( :ons_id => result.ward_code )
  19. redirect "/wards/#{@ward.slug}/postcode/#{@postcode}"
  20. end
  21. haml :home
  22. end
  23. get '/wards/:slug/postcode/:postcode/?' do
  24. @ward = Ward.first(:slug => params[:slug])
  25. @postcode = params[:postcode]
  26. haml :wards
  27. end
  28. get '/wards/:slug/?' do
  29. @ward = Ward.first(:slug => params[:slug])
  30. haml :wards
  31. end
  32. get '/wards/?' do
  33. @wards = Ward.all
  34. haml :wardlist
  35. end
  36. get '/results/uk-parliament/2010-05-06/:constituency' do
  37. if params[:constituency] == 'carshalton-and-wallington'
  38. const = 1
  39. else
  40. const = 2
  41. end
  42. @constituency = Constituency.get(const)
  43. @candidates = Parliamentcandidate.all(:constituency_id => const, :order => [ :votes_2010.desc ])
  44. @total_2010 = Parliamentcandidate.sum(:votes_2010, :constituency_id => const)
  45. haml :resultsukparliament
  46. end
  47. get '/how-the-council-election-works' do
  48. haml :election
  49. end
  50. get '/how-the-parliament-election-works' do
  51. haml :parliament
  52. end
  53. # get '/voting' do
  54. # haml :voting
  55. # end
  56. get '/error' do
  57. haml :error
  58. end
  59. get '/about' do
  60. haml :about
  61. end
  62. get '/aliens' do
  63. haml :aliens
  64. end
  65. not_found do
  66. haml :not_found
  67. end