Przeglądaj źródła

Added error checking for invalid postcodes and postcodes outside Sutton borough

tags/last-sinatra-version
Adrian Short 14 lat temu
rodzic
commit
deb1bb8a7c
4 zmienionych plików z 24 dodań i 7 usunięć
  1. +13
    -1
      app.rb
  2. +1
    -1
      views/_register-to-vote.haml
  3. +6
    -0
      views/aliens.haml
  4. +4
    -5
      views/error.haml

+ 13
- 1
app.rb Wyświetl plik

@@ -25,10 +25,18 @@ get '/wards' do
# Postcode not found/invalid
# Postcode valid but not in LB Sutton
unless result = Pat.get(@postcode)
result = Pat.get(@postcode)

if result.code == 404
redirect '/error'
end

@district_name = result['administrative']['district']['title']
if @district_name != "Sutton London Borough Council"
redirect '/aliens'
end
@ward_name = result['administrative']['ward']['title']
@ward = Ward.first( { :name => @ward_name } )
@council_candidates = Councilcandidate.all( :ward_id => @ward.id, :order => [ 'surname' ])
@@ -55,3 +63,7 @@ end
get '/about' do
haml :about
end

get '/aliens' do
haml :aliens
end

+ 1
- 1
views/_register-to-vote.haml Wyświetl plik

@@ -9,4 +9,4 @@
You can get a registration form at the
%a{ :href => "http://www.aboutmyvote.co.uk/" } About My Vote
website or by phoning Sutton Council on
%span{ :class => 'phone' } 020 8770 4888.
%span.phone 020 8770 4888.

+ 6
- 0
views/aliens.haml Wyświetl plik

@@ -0,0 +1,6 @@
.grid_12
%h1 You're not from round these parts…
%p This site only has information about elections in the London Borough of Sutton.
%p Your postcode is outside Sutton. Sorry, we can't help you further.

+ 4
- 5
views/error.haml Wyświetl plik

@@ -1,5 +1,4 @@
%h1 Not Found

%p That's an invalid postcode or one that's not in the London Borough of Sutton.

%p Sorry, we can't help you further.
.grid_12
%h1 Invalid postcode
%p
%a{ :href => "/" }Please go back and try again

Ładowanie…
Anuluj
Zapisz