apneadiving/Google-Maps-for-Rails — pull request #328 by fiedl (2013-03-19 02:06:25+00:00)
Title: Turbolinks Support

Using a callback in `lib/gmaps4rails/js_builder.rb` adds support for the `turbolinks` gem. This should, thereby, solve Issue #320.

I'm sorry, I couldn't test if this breaks your tests, since the tests for the `master` branch are not green on my machine (before changing anything).

### What I've changed:

If you can't use this pull request, here's what I did:

In `lib/gmaps4rails/js_builder.rb`, in `create_js`, within `if load_map?`, add the following line:

```ruby
@js << "$(document).on('page:load', function() { if( $('.gmaps4rails_map').length > 0 ) { Gmaps.loadMaps(); } });"
```

This will create a callback for turbolinks, which triggers `Gmaps.loadMaps()` when a page is loaded via turbolinks. The line also checks if there's a map displayed on the page. Because otherwise, if you first open a page with a map, and then go to another page without map, turbolink will still call this callback.

### Test this on your project

To test this modification on another project or your test app, add my fork to the `Gemfile` of the test project, temporarily:

```ruby
gem 'gmaps4rails', '>= 2.0.0.pre', git: 'https://github.com/fiedl/Google-Maps-for-Rails.git'
```