Ruby on Rails code download

The Ruby on Rails code is ready to downloaded. Here’s how to get it up and running in your environment:

  1. Download the zip file, gmaps_rails_code.zip
  2. Create your own empty Rails application (rails your_app_name)
  3. Unzip gmaps_rails_code.zip in the root of your newly created application. When you unzip the file, you will see it contains five root directories: app, db, lib, public, standalone_scripts. You want these directories to overlay the directories of your own Rails application.
  4. set up your config/database.yml as appropriate for your environment. Most people just use root/no password for their development environment.
  5. in routes.rb, add a line to configure the home_url: map.home '', :controller => 'app', :action=>'index'
  6. run rake db:migrate to load the schema.
  7. In your config/environments/development.rb, add a line to specify your own Google Maps API key:
    GOOGLE_MAPS_KEY=’your-google-maps-api-key’
  8. Start your rails server, and go to http://localhost:3000/app (or adjust if your server is on a different port). You should see a welcome page and links to all the chapter examples.

These steps will give you the code and an empty database. This is meant to set the stage for you work with the various examples in the book. You will need to run the various data imports (capitol city scaping, FCC structure import, TIGER/Line data processing, etc) per the instructions in the book to fully populate the database.

After following the steps here, the examples in chapters 2,3,9, and 10 should work immediately. The rest of the chapters require some amount of data (primarily the FCC towers data), so you will need to load that data for the examples to work.

Notes

The Google Maps key is the primary configuration setting you need to get started. There are some others you will need for later chapters, however. You can add these to config/environments/development.rb file as well:

TIGERLINE_DIR="/path/to/your/tigerline/data"
YAHOO_API_KEY="your_yahoo_api_key"
UK_POSTCODE_DIR="/path/to/your/uk/postcode/data" #the directory, not the file

Finally, note that the Ruby on Rails examples are live at http://book.earthcode.com.


29 Responses to “Ruby on Rails code download”  

  1. 1 Pier Luigi

    i just can’t make your code run on my machine. this is my error while running rake:

    livebox:~/work/maps gleeman$ rake db:migrate
    (in /Users/xxxxxx/work/maps)
    rake aborted!
    uninitialized constant ActionController
    /Users/xxxxxx/work/maps/rakefile:10
    (See full trace by running task with –trace)
    livebox:~/work/maps gleeman$

    what should i do ?

  2. 2 Pier Luigi

    problem solved, it was a bug on my environment

    i compiled readline and ruby as described in this tutorial:
    http://hivelogic.com/narrative/articles/ruby_rails_lighttpd_mysql_tiger?status=301

  3. 3 Rick

    I see the same problem using the Locomotive install of Ruby on OSX. If anyone knows the solution to this, rather than having to build Ruby from scratch that would be handy!

  4. 4 kaushik

    pls help me its not working in instant rails

  5. 5 Andre

    Hi Kaushik, drop me an email at theauthorsof[at]googlemapsbook.com and describe the specific problems you are having in a little more detail — error messages, log file entires, etc.

    Cheers,

    Andre

  6. 6 Howard

    Andre,

    I’m a newbie on RoR and I’ve having the same uninitialized error for ActionController with InstantRuby/RadRail environment.

    Howard

  7. 7 Andre

    == Instant Rails Users ==

    I was able to get the examples up and running by deleting two files in the app’s lib/tasks directory: importing_tasks.rake and scraping_tasks.rake. If you delete those two, you’ll be able to get started, run rake db:migrate, etc. Of course, you’ll eventually need to figure out why Instant Rails has a problem with those specific rake tasks. Note that in importing_tasks.rake, Instant Rails chokes on the require ‘application’ line.

  8. 8 Patrick

    I’m getting a FireBug JS error when I try to run your sample at http://book.earthcode.com/chap_eleven/tigerline_geocoder. The address is of a friend of mine there and is valid: 475 26th Ave.

    I haven’t yet read your book. Just learned about it tonight but will be buying it for sure. Just wanted to try the samples and got the error.

  9. 9 Patrick

    I’m getting a FireBug JS error when I try to run your sample at http://book.earthcode.com/chap_eleven/tigerline_geocoder. The address is of a friend of mine there and is valid: 475 26th Ave.

    a has no properties
    zc(null)maps2.77.api.js (line 30)
    o(null, Object)maps2.77.api.js (line 372)
    a(null, Object)maps2.77.api.js (line 1213)
    init()chap_eleven_tiger… (line 17)
    [Break on this error] function zc(a){var b;while(b=a.firstChild){ce(b);a.removeChild(b)}}

    I haven’t yet read your book. Just learned about it tonight but will be buying it for sure. Just wanted to try the samples and got the error.

  10. 10 Victor

    Enjoying the book so far (Rails version). But I have a question. I was getting errors in Firebug regarding undefined latlng in the init() function from the code in chapter 3 until I compared it to the downloadable code. The difference is the “if (overlay==null)” check you’ve added in the GEvent.addListener closure to wrap the building of the inputForm. When I add that check in, the errors are resolved, so I’m guessing there is more than one callback happening here and it’s only when the GOverlay isn’t returned that a GLatLng is? Could you please explain what’s going on there?

    Cheers.

  11. 11 Jim G

    Andre,

    I should mention that the problem described by Pier and others is not confined to Instant Rails. I have a fairly standard* Ruby and Rails install on Windows XP. I was seeing the same error and find that removing the two tasks files clears up the error.

    I suspect that the problem has to do with the tasks files relying on the definition of the Yahoo! API key, the Tiger data path, or the UK geocoding data path.
    I haven’t yet tested this theory.

    Kind regards,
    Jim Greer

    *
    - One-click Ruby Installer, http://rubyforge.org/frs/?group_id=167
    - gem install rails (1.2.3)

  12. 12 Andre

    @Patrick — I see that error too with addresses that don’t geocode properly. You should expect to find addresses which are misplaced or simply fail to geocode using the stock TIGER/Line data; the data just isn’t that airtight. As far as the JS error, that’s sloppy error handling on my part :-)

  13. 13 Andre

    @ Victor: yes, I remember this one, although I can’t recall why the onclick is triggering multiple events.

    @ Jim G: most likely the problem is with the scraping tasks rakefile if you don’t already have scrAPI installed.

    By the way, I have become enamored with _why’s Hpricot library since writing the book. I strongly encourage everyone to take a look at it. I even use it for parsing XML, although it’s primarily designed as an HTML parser.

  14. 14 Richo

    Hi Guys.

    Bought the book and am currently digesting it. Excellent work.

    I have been running InstantRails, so was happy to find this page, so I could get the code to work. Maybe you want to make it easier to find for other people who also purchsed the book.

    OK cheers

    R.

  15. 15 Aruna

    I am new ROR and wanted to try the samples given here. I have followed all the istructions but unable to start my webserver. here is what iam getting when I am trying to start my web server

    C:\InstantRails\rails_apps\map>ruby script/server webrick
    => Booting WEBrick…
    ./script/../config/../config/environments/development.rb:23:in `load_environment
    ‘: compile error (SyntaxError)
    ./script/../config/../config/environments/development.rb:23: Invalid char `\222′
    in expression
    ./script/../config/../config/environments/development.rb:23: Invalid char `\222′
    in expression from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib
    /initializer.rb:204:in `load_environment’
    from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib
    /active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings’
    from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initial
    izer.rb:201:in `load_environment’
    from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initial
    izer.rb:85:in `process’
    from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initial
    izer.rb:43:in `send’
    from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/initial
    izer.rb:43:in `run’
    from ./script/../config/../config/environment.rb:13
    from C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require
    .rb:27:in `gem_original_require’
    … 10 levels…
    from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/command
    s/server.rb:39
    from C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require
    .rb:27:in `gem_original_require’
    from C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require
    .rb:27:in `require’
    from script/server:3

    I really appreciate your help

    Thanks in advance
    Aruna

  16. 16 Andre Lewis

    Hi Aruna, I think the key is the line:

    ./script/../config/../config/environments/development.rb:23: Invalid char `\222′
    in expression

    My advice is to check your development.rb for any corrupted or extraneous characters.

  17. 17 Jon

    Am I the only one having problems with the downloaded source code not matching the code in the book?

    I swear every time I go to compare, there are small differences, functions are named different, variables are named different, some syntax is different. It’s driving me crazy. It’s impossible to check your work against a working sample.

  18. 18 Ravi Vardhan

    i want to integrate google map with my rails application
    -code require for above problem

    please help me

  19. 19 Doug

    Note that “found” and “left” are SQL keywords, thus the markers table migration fails on a database like JavaDB (I’m using JRuby on Rails).

  20. 20 Sandra

    hi, i’m getting a mysqlimport not recognized as an internal or external command when running the following import [page 107 in the book]:

    mysqlimport –delete –fields-terminated-by=’|’ –columns=
    unique_si,lat_deg,lat_min,lat_sec,lat_dir,latitude,long_deg,long_min,
    long_sec,long_dir,longitude –user=root –local maps_development fcc_locations.dat

    i’m using instantrails on windows.

    thanks for any help

  21. 21 Charles Kogge

    I have the Rails book. In Listing 3-5 in the book, the createMarker() function does not look anything like the code download named chap_three_final.js

    Why is this so? Thank you.

  22. 22 Andre Lewis

    @Charles, @Jon - the code went through some changes after the book was published. Sorry for any frustration the discrepancies have caused.

  23. 23 Charles Kogge

    Another issue - Ronjon’s “stores.yml”. Maybe it exists somewhere, but I’ve spent the last hour looking for it in the download code and the Ronjon site, and I can’t find it. I’ve found a “stores.XML file somewhere (I forget exactly where now). “stores.yml” and all the other listings whould appear in the download file. Please get out ahead of me and your other readers now by reviewing Chapters 4 and beyond, adding all of the files that are needed. Thanks.

  24. 24 Andre

    Hi Charles, good eye. Hopefully you got the stores.yml file I emailed you yesterday, and I have also put up test/fixtures/stores.yml the Rails code zip file download.

    Cheers,

    Andre

  25. 25 Andre

    @Sandra — I don’t have ready access to an Instant Rails installation these days. My best guess is that Instant Rails’ mysql binary isn’t in your path. You can either modify your path to include the mysql binary, or cd into into where ever mysqlimport lives in your Instant Rails installation.

  26. 26 Charles

    On page 84, the section named “Yahoo Geocoder Requests”. You need a Yahoo API key, which you say on page 82 is “application specific”. So what is the Web Application URL (For example: ‘http://myapp.com/welcome.html’) that someone should enter on the YAHOO API Registration page (http://developer.yahoo.com/wsregapp/index.php) that the reader of your book can use for the rake task (listing 4-6) on page 85?

  27. 27 Jean Moreau

    @Aruna

    The problem is with GOOGLE_MAPS_KEY=’your-google-maps-api-key’ found in the instructions

    It should be GOOGLE_MAPS_KEY=”your-google-maps-api-key”

    Note the double quotes

  28. 28 Charles

    Many things are going wrong here. First of all, Sandra’s problem is one that I encountered and solved yesterday. They are typos in the book. I just sent you an email.

    And the code differences that Jon mentioned, as well as many sections of code missing from the ZIP file, waste the reader’s time and make it a real hassle to understand what’s going on. The book is good, but these items need to be addressed now.

    Is there a later version of the book we can all get to stop the confusion? Here is the info from my book:
    Copyright 2007
    ISBN-13 (pbk): 978-1-59059-787-3
    ISBM-10 (pbk): 1-59059-787-7

  29. 29 Andre

    @Charles: Yahoo requests that you create a key for each application, but at the time of writing it wasn’t actually required to run your app. For geocoding purposes (I’m not sure about displaying maps), you can enter a pseudo-url like http://localhost

    @Jean, @Aruna — the single quote and double quote in Ruby are essentially identical except that the single quote does not allow interpolation. If the single quote character is the problem (perhaps because it was typed or copied as “curly quotes”), it can be replaced with normal single quotes or normal double quotes.


Buy Our Books!

(Here's Why) PHP book Rails book DOM book mashups book