嗨,我目前正在经历本教程使用gmap4rails使用Gmap4Rails宝石没有错误,但地图是没有得到显示
我很新的这宝石,所以我只是要通过引导一步步。
我有一个cities_controller.rb
class CitiesController < ApplicationController
def index
@cities = City.all
@json = @cities.to_gmaps4rails
end
end
我有一个city.rb我的模型
class City < ActiveRecord::Base
acts_as_gmappable
has_many :neighborhoods
def gmaps4rails_address
"#{self.name}, #{self.state}"
end
end
这是我的index.html.erb内我的城市我的视图文件夹
文件夹里面<%= gmaps4rails(@json) %>
我增加了gem跑安装程序以及。
在我的应用程序的布局,我有这个在我的身上
<%= yield :scripts %>
这是我的架构
ActiveRecord::Schema.define(version: 20130714194244) do
create_table "cities", force: true do |t|
t.string "name"
t.string "state"
t.float "latitude"
t.float "longitude"
t.boolean "gmaps"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "population"
end
我却越来越没有错误,我接种这些
City.create(name: "New york" ,state: "NY", population: 8175133)
City.create(name: "Los Angeles",state: "CA", population: 3792621)
City.create(name: "Chicago",state: "IL", population: 2695598)
City.create(name: "Houston",state: "TX", population: 2099451)
City.create(name: "Philadelphia",state: "PA" , population: 1526006)
City.create(name: "Phoenix",state: "AZ", population: 1445632)
City.create(name: "San Antonio",state: "TX", population: 1327407)
City.create(name: "San Diego",state: "CA", population: 1307402)
City.create(name: "Dallas",state: "TX", population: 1197816)
City.create(name: "San Jose",state: "CA", population: 945942)
数据库
当我打开我的滑轨控制台并做City.all
我注意到我的经度和纬度已经计算出来,这意味着宝石工作正常。
#<City id: 1, name: "New york", state: "NY", latitude: 40.7143528, longitude: -74.00597309999999, gmaps: true, created_at: "2013-07-14 19:51:32", updated_at: "2013-07-14 19:51:32", population: 8175133>
我是否缺少一些api密钥?当我做铁轨时,我得到的只是一个空白的屏幕?至少我应该看到一张地图。这可能是一个js问题,我不太确定。
谢谢!
检查你的'app/assets/javascripts'文件夹,你有'gmaps4rails'文件夹吗?另外,你可以发布你的内容“app/assets/javascripts/application.js”吗? – David
@David嘿我明白了,它已经解决了。事实证明,该宝石与红宝石2.0和导轨4的问题。我切换回红宝石1.9.3p429和轨道3.2.13。 js文件最初是在我的公共文件夹中创建的,它不正确,它应该已经在我的资产文件夹中生成。 – Jngai1297