0

我一直在試圖讓gmaps4rails工作幾個小時。我認爲這是加載順序,我甚至嘗試使用rails 3.2和ruby 1.9.3來克隆演示應用程序 - 仍然顯示沒有標記的空白地圖。我的JSON在模型中是正確的。JS使用資產管道3.2中的Gmaps4Rails加載順序

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

- application.html.erb(自舉)

<!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」 端

- - 模式

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 

* - 我的視圖*

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

* - 我的JSON從視圖*

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

回答

1

對不起閱讀你所浪費的時間:它不是我的寶石:)

的目的,我沒有看到你的佈局yield :scripts。這是該項目主頁中規定的強制性先決條件之一。

0

在您的控制器視圖和<%= javascript_include_tag「應用程序」%>之前放置yield:scripts。 (例如將其放在application.html.erb的標題中)

希望它有幫助。我在這拉了一個小時的頭髮......

相關問題