【问题标题】:Rails3: Gem Gmap4rails with mongoid doesn't show mapRails3:带有mongoid的Gem Gmap4rails不显示地图
【发布时间】:2012-05-22 09:53:47
【问题描述】:

我按照 github 上的说明安装了所有东西。 (Gmaps4Rails-github)

问题是地图是空白的,我从css只看到地图的边框。

型号:

class Recipe
  include Mongoid::Document
  include Gmaps4rails::ActsAsGmappable
  acts_as_gmappable 

  field :name, :type => String
  field :city, :type => String
  field :country, :type => String
  field :latitude, :type => Float
  field :longitude, :type => Float
  field :gmaps, :type => Boolean

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

控制器:

class RecipesController < ApplicationController
  def index
   @location = Recipe.all.to_gmaps4rails
  end
end

查看:

= gmaps4rails(@location)

@location 在数组中包含 lat 和 lng,例如

[{"lat":13.055363,"lng":47.811886},{"lat":13.055363,"lng":47.811886}]

正在加载所需的 JS 和 CSS 文件: gmaps4rails.base.js、gmaps4rails.googlemaps.js、gmaps4rails.bing.js、gmaps4rails.mapquest.js、gmaps4rails.openlayers.js、gmaps4rails.css

我在服务器日志或 JS 控制台中没有收到任何错误。我不知道我在这里做错了什么。

任何建议都会非常有帮助!谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 mongoid gmaps4rails


    【解决方案1】:

    我看不到任何提及:

    <%= yield :scripts %>
    

    在您的代码中。这是强制性的!

    【讨论】:

    • 非常感谢!我认为通过 Rails 资产管道加载所需的 js 文件就足够了。
    猜你喜欢
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多