Quellcode durchsuchen

Initial commit

tags/last-sinatra-version
Adrian Short vor 14 Jahren
Commit
27173076c9
1 geänderte Dateien mit 53 neuen und 0 gelöschten Zeilen
  1. +53
    -0
      app.rb

+ 53
- 0
app.rb Datei anzeigen

@@ -0,0 +1,53 @@
require 'rubygems'
require 'sinatra'
require 'json'
require 'rest_client'

get '/' do
@wards = %w{ Cheam Sutton Stonecot }
haml :home
end

get '/wards' do
@postcode = params[:postcode].strip.upcase

url = "http://www.uk-postcodes.com/postcode/" + @postcode.gsub(/ /, '') + '.json'

result = RestClient.get(url)
result_ary = JSON.parse(result)
@district_name = result_ary['administrative']['district']['title']
@ward_name = result_ary['administrative']['ward']['title']
haml :wards
end

__END__

@@layout
!!!
%html
%head
%title Find My Candidates
%body
#main
%h1 Find My Candidates
= yield
#footer
%hr/
%p Design by Adrian Short
@@home
%form{ :method => 'get', :action => '/wards' }
%label{ :for => "postcode" }
Postcode
%input{ :type => 'text', :name => 'postcode', :size => 10 }
%input{ :type => 'submit', :value => "Find" }
- for ward in @wards
%p= ward
@@wards
%h2
#{@ward_name} Ward in #{@district_name}
%p
Your postcode is #{@postcode}

Laden…
Abbrechen
Speichern