Election results in the London Borough of Sutton.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

92 lignes
1.9 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. @wards = Ward.all
  22. haml :home
  23. end
  24. get '/wards/:slug/postcode/:postcode/?' do
  25. @ward = Ward.first(:slug => params[:slug])
  26. @postcode = params[:postcode]
  27. haml :wards
  28. end
  29. get '/wards/:slug/?' do
  30. @ward = Ward.first(:slug => params[:slug])
  31. haml :wards
  32. end
  33. get '/wards/?' do
  34. @wards = Ward.all
  35. haml :wardlist
  36. end
  37. get '/results/uk-parliament/2010-05-06/:constituency' do
  38. if params[:constituency] == 'carshalton-and-wallington'
  39. const = 1
  40. else
  41. const = 2
  42. end
  43. @constituency = Constituency.get(const)
  44. @candidates = Parliamentcandidate.all(:constituency_id => const, :order => [ :votes_2010.desc ])
  45. @total_2010 = Parliamentcandidate.sum(:votes_2010, :constituency_id => const)
  46. haml :resultsukparliament
  47. end
  48. get '/results/sutton-council/2010-05-06/:slug' do
  49. @ward = Ward.first(:slug => params[:slug])
  50. @candidates = Councilcandidate.all(:ward_id => @ward.id, :order => [ :votes_2010.desc ])
  51. @total_2010 = Councilcandidate.sum(:votes_2010, :ward_id => @ward.id)
  52. haml :resultssuttoncouncil
  53. end
  54. get '/how-the-council-election-works' do
  55. haml :election
  56. end
  57. get '/how-the-parliament-election-works' do
  58. haml :parliament
  59. end
  60. # get '/voting' do
  61. # haml :voting
  62. # end
  63. get '/error' do
  64. haml :error
  65. end
  66. get '/about' do
  67. haml :about
  68. end
  69. get '/aliens' do
  70. haml :aliens
  71. end
  72. not_found do
  73. haml :not_found
  74. end