Discuss This Topic
There are 0 comments in this discussion.
The steps necessary to get the Google Maps for Rails gem, which is designed for Rails 3 and above, working with a Rails 2.3 application.
The Kete application has the option of providing Google Maps interfaces for both viewing location data and setting it. At the time of this writing, it uses Google Maps API version 2. Lately we've been getting strange errors due to version 2's depreciation in favor of version 3. So I'm working on upgrading Kete, which at the moment is a based on Ruby on Rails version 2.3.5, to use Google Maps API version 3. To that end, I'm switching Kete's custom code and use of YM4R to use the Google Maps for Rails gem.
Although there are many options for libraries that integrate Google Maps Javascript API Version 3 with Ruby on Rails, Google Maps for Rails looks to have the cleanest API, be the most used, and the best supported. @apneadiving seems particularly good about answering questions on Stack Overfow.
The difficulty is that Google Maps for Rails (also called gmaps4rails), is designed to be used as a Rails Engine on Rails 3 or above. The good news is that I've gotten it working with Rails 2.3.x with some workarounds. They aren't necessarily pretty, but they work. Here they are:
gem install gmaps4rails
) as it suits yourequire 'gmaps4rails/base'
# skipping require 'gmaps4rails/acts_as_gmappable' as I don't need it for my project
require 'gmaps4rails/extensions/array'
require 'gmaps4rails/extensions/hash'
require 'gmaps4rails/helper/gmaps4rails_helper'
ActionController::Base.send :helper, Gmaps4railsHelper
cd public/javascripts
mkdir gmaps4rails
cd gmaps4rails
curl -L https://raw.github.com/apneadiving/Google-Maps-for-Rails/master/public/javascripts/gmaps4rails/gmaps4rails.base.js -O
curl -L https://raw.github.com/apneadiving/Google-Maps-for-Rails/master/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js -O # note I skipped other providers (Bing, OpenLayers), as don't need them, add curl -L ... if you do
cd ../../stylesheets
curl -L https://raw.github.com/apneadiving/Google-Maps-for-Rails/master/public/stylesheets/gmaps4rails.css -O
You should now have a shiny new Google Map! Enjoy.
I've skipped the version control commands I've used (i.e. git add javascripts/gmaps4rails, etc.). Use them as appropriate to your project.
Note: I haven't tested this with the acts_as_gmappable functionality in the model. I've only tested it by feeding JSON objects directly to the gmaps4rails view helper. So there may be additional steps to get acts_as_gmappable working.