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.

app.rb 1.8 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 '/results/sutton-council/2010-05-06/:slug' do
  48. @ward = Ward.first(:slug => params[:slug])
  49. @candidates = Councilcandidate.all(:ward => @ward, :order => [ :votes_2010.desc ])
  50. @total_2010 = Councilcandidate.sum(:votes_2010, :ward_id => @ward.id)
  51. haml :resultssuttoncouncil
  52. end
  53. get '/how-the-council-election-works' do
  54. haml :election
  55. end
  56. get '/how-the-parliament-election-works' do
  57. haml :parliament
  58. end
  59. # get '/voting' do
  60. # haml :voting
  61. # end
  62. get '/error' do
  63. haml :error
  64. end
  65. get '/about' do
  66. haml :about
  67. end
  68. get '/aliens' do
  69. haml :aliens
  70. end
  71. not_found do
  72. haml :not_found
  73. end