Home     Show Politicians   Show Locations   Scrape your Own
How did I do this. Ruby on Rails and JavaScript. Hpricot and Prototype. Ajax and iframes. Click on one of the categories on the left to see more info.
Well, this runs in a small virtual host under Apache 2.0. The virtual host is not set up for Ruby on Rails, it's kindof old-fashioned, Perl and PHP and .htaccess work well, but everything else is painful. Like RoR. No root access. Not even FCGI, this runs RoR under old-style CGI, held together with Apache rewrite voodoo. It's kindof slow. It is not scalable to multiple servers, as I took certain liberties, because this site will never be deployed multi-server. This wouldn't be hard to fix, though. OK so it was a big hassle to get it working in my virtual host but now it's going pretty well. See files in the public directory, especially public/production.cgi and public/fs_dispatch.rb and config/environments/production.rb.
There is a ton of ajax. The districts page works by ajax subDistricts for every district that has subdistricts, see app/views/vu/districts.html.erb. Same for the row of location menus (bottom) in the Describe page in the scraper wizard, see app/views/acquire/desc.html.erb. The ajax frogLookup does the Search in the frogs page The ajaxes frogSummary and distSummary provide the info on the right half panel on the frogs and districts pages, respectively. Egads, the source on this page is also served by ajax! There's new ajax commands being created all the time; I just intuitively make something ajax when it feels like it should be interactive. See app/controllers/ajax_controller.rb and the associated view files for the full story.
The browser in the scraper wizard (Scrape Your Own) pumps everything through hpricot on the server (app/controllers/scrape_controller.rb), into an iframe on the client (app/views/acquire/browse.html.erb). This is not really 'ajax' although some would call it that. All of the Hpricot work is done by the Edit phase; the rest is the user supplying details.
  • The Vu controller is for pages that simply display info. app/controllers/vu_controller.rb
  • The Acquire controller is the 'Scrape Your Own' wizard. app/controllers/acquire_controller.rb
  • The Ajax controller handles all ajax calls, and a few others whose output is meant for machine use only. app/controllers/ajax_controller.rb
  • The Scrape controller filters all browse HTML in the scrape wizard. The data must be served from our server, otherwise cross-domain security problems get in the way. So the server actually retrieves the HTML, and pre-digests it for a subsequent pick page. This was hard to get right. app/controllers/scrape_controller.rb
  • The Revise controller is for pages that make detailed edits on the data. Its frogs and districts pages use the same selection partials in the shared directory as the vu controller. It's not really public yet. app/controllers/revise_controller.rb
Uml Offices, Parties and Realms are simply names mapped to IDs. So all the Christian Democrat parties in the world map to the same Parties record, even though they may have nothing to do with each other. Similarly, US Senators, California Senators and Nigerian Senators all share the same offices record for 'Senator'. This may change in the future for Parties, but not for the others. Districts are hierarchical thru the enclosing_id field. Frogs and Districts have a many-many relationship through the Terms table.
Backup is done through the ajax/backup view in app/views/ajax/backup.html.erb. The result is a ruby file of ActiveRecord .new calls that will reconstruct the database. The backup file contains no actual record IDs, so that parts of different backup files can be merged by just copying and pasting. Foreign key IDs are reconstructed via name lookup method g() on most table classes, being generated by method gId() on those same classes. As of this writing, the file is past 500k and growing fast.
District.new(:name=>"California", :abbr=>"CA", :enclosing=>District.g("United States"), :realm=>Realm.g("State"), :pict=>nil).save!
Frog.new(:first_name=>"Arnold", :last_name=>"Schwarzenegger", :party=>Party.g("Republican"), :pict=>"100,118,http://upload.wikimedia.org/wikipedia/commons/thumb/3/37/Arnold_Schwarzenegger.jpg/100px-Arnold_Schwarzenegger.jpg").save!
Term.new(:office=>Office.g("Governor"), :frog=>Frog.g("Arnold","Schwarzenegger"), :district=>District.g("California","United States"), :starting_date=>Date.civil(2003,1,1), :ending_date=>Date.civil(2010,1,1)).save!
		
And, ah, what, bbedit on MacOS X. Macs Rock. Thanks to Rails' ability to run a test server just about anywhere, I can take my laptop (MacBook Pro or Linux multiboot) and do development while hermetically sealed from the outside world. (Unlike most of my jobs where the test servers barely run on the test machines. And one must be connected to The Borg to test anything.) Well, some oxygen and electricity helps if it's more than a few hours. And, coffee and a bathroom help a lot.

click a file to view
app/controllers/acquire_controller.rb
app/controllers/acquire_controller.rb.4
app/controllers/acquire_controller.rb.b4succAlpha
app/controllers/ajax_controller.rb
app/controllers/ajax_controller.rb.4
app/controllers/ajax_controller.rb.5
app/controllers/application.rb
app/controllers/revise_controller.rb
app/controllers/scrape_controller.rb
app/controllers/vu_controller.rb
app/helpers/acquire_helper.rb
app/helpers/ajax_helper.rb
app/helpers/application_helper.rb
app/helpers/revise_helper.rb
app/helpers/scrape_helper.rb
app/helpers/vu_helper.rb
app/models/district.rb
app/models/frog.rb
app/models/office.rb
app/models/party.rb
app/models/realm.rb
app/models/term.rb
app/views/acquire/_pick_more.html.erb
app/views/acquire/_pick_one.html.erb
app/views/acquire/_pick_zero.html.erb
app/views/acquire/browse.html.erb
app/views/acquire/cols.html.erb
app/views/acquire/desc.html.erb
app/views/acquire/edit.html.erb
app/views/acquire/finish.html.erb
app/views/acquire/intro.html.erb
app/views/acquire/pick.html.erb
app/views/ajax/a.erb
app/views/ajax/backup.html.erb
app/views/ajax/distSumData.html.erb
app/views/ajax/distSummary.html.erb
app/views/ajax/frogLookup.html.erb
app/views/ajax/frogSumData.html.erb
app/views/ajax/frogSummary.html.erb
app/views/ajax/getSource.html.erb
app/views/ajax/subDistricts.html.erb
app/views/layouts/ajax.html.erb
app/views/layouts/application.html.erb
app/views/layouts/scrape.html.erb
app/views/polSynonyms.txt
app/views/revise/districts.html.erb
app/views/revise/frogs.html.erb
app/views/revise/offices.html.erb
app/views/revise/parties.html.erb
app/views/revise/prefs.html.erb
app/views/revise/realms.html.erb
app/views/revise/terms.html.erb
app/views/scrape/ping.html.erb
app/views/scrape/scraped.html.erb
app/views/shared/_display_panel.html.erb
app/views/shared/_district_chooser.html.erb
app/views/shared/_frog_chooser.html.erb
app/views/vu/bug_list.html.erb
app/views/vu/districts.html.erb
app/views/vu/frogs.html.erb
app/views/vu/source.html.erb
app/views/vu/welcome.html.erb
lib/db_utils.rb
lib/fs_utils.rb
public/images/UML.png
public/images/arrowBlank.png
public/images/arrowDiag.png
public/images/arrowDown.png
public/images/arrowRight.png
public/images/frog_scraper.jpg
public/images/idle.gif
public/images/idle.html
public/images/rails.png
public/images/title.png
public/stylesheets/backButton.png
public/stylesheets/backButtonActive.png
public/stylesheets/backButtonDisabled.png
public/stylesheets/backButtonHover.png
public/stylesheets/foreButton.png
public/stylesheets/foreButtonActive.png
public/stylesheets/foreButtonDisabled.png
public/stylesheets/foreButtonHover.png
public/stylesheets/fs.css
public/stylesheets/fs_left_shadow.png
public/stylesheets/fs_title.png
public/stylesheets/fs_top_shadow.png
public/stylesheets/politicsBanner.jpg
public/stylesheets/shadow2.gif
public/javascripts/application.js
public/javascripts/controls.js
public/javascripts/dist_tree.js
public/javascripts/dragdrop.js
public/javascripts/effects.js
public/javascripts/frog_hash.js
public/javascripts/prototype.js
public/fs_dispatch.rb
public/production.cgi
public/blizdev.cgi
test/fixtures/districts.yml
test/fixtures/frogs.yml
test/fixtures/offices.yml
test/fixtures/parties.yml
test/fixtures/realms.yml
test/fixtures/terms.yml
test/unit/acquire_test.rb
test/unit/district_test.rb
test/unit/frog_test.rb
test/unit/office_test.rb
test/unit/party_test.rb
test/unit/pickTableLabel_test.rb
test/unit/realm_test.rb
test/unit/term_test.rb

source:


Have I told you that I'm looking for a job? I wrote this out of boredom between jobs. Actually by the time you read this I could have a job, check here. I've been learning Ruby on Rails off and on for years. This site is here to demonstrate the kind of work that I do. It is running in a virtual host with no Ruby support, but I got Rails working anyway. Click Here to see source. Click here to go see the rest of Allan's portfolio.     - Allan