Search code examples
ruby-on-railsjsonasset-pipelineruby-on-rails-3.2gmaps4rails

JS load order of Gmaps4Rails in rails 3.2 using asset pipeline


I've been trying to get gmaps4rails working for hours. I think it's the load order, I even tried cloning a demo app using rails 3.2 and ruby 1.9.3-- still showing a blank map with no markers. My JSON is correct from the model.

Project: https://github.com/apneadiving/Google-Maps-for-Rails

-- application.html.erb (bootstrapped)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <%= javascript_include_tag "application" %>
    <%= stylesheet_link_tag "application", :media => "all" %>
  </head>
  <body>
    <%= yield %>
    <%= javascript_include_tag "application" %>
  </body>
</html>

-- Gemfile

gem "gmaps4rails", "~> 1.4.8"

-- Application.js

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require gmaps4rails/gmaps4rails.base
//= require gmaps4rails/gmaps4rails.googlemaps
//= require_tree .

-- user.rb

acts_as_gmappable

def gmaps4rails_address "#{self.address}, #{self.city}" end

-- schema

  create_table "users", :force => true do |t|
    t.string   "name"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.string   "address"
    t.string   "city"
    t.float    "latitude"
    t.float    "longitude"
    t.boolean  "gmaps"
  end

-- UsersController

 def index
    @bars = User.all
    @json = User.all.to_gmaps4railsrespond_to do |format|
  format.html # index.html.erb
  format.json { render json: @users }
end

end

*-- my view *

<%= gmaps4rails(@json) %>
<%= @json %>

*-- my json printed from the view *

[{"lat":37.7381599,"lng":-122.3803166},{"lat":37.5121003,"lng":-122.2009814},{"lat":33.9964092,"lng":-118.4725106}]

Solution

  • Sorry to read you wasted time: it's not the purpose of my gem :)

    I don't see yield :scripts in your layout. It's one of the mandatory prerequisites stated in the project's homepage.