2011-11-16 67 views
2

我有一个显示页面,应该显示业务的业务和Google地图。我使用谷歌地图API v3。我已经需要//= require gmaps4rails/googlemaps.jsapplication31.js,并加入以下行到模型(business.rb):使用Rails 3.1的Google Maps for Rails(gmaps4rails)“未定义Gmaps”

acts_as_gmappable 

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

样式表还需要(包括在内)。我还将gem'gmaps4rails'包含到Gemfile中并捆绑在一起。我的模型具有数据库中正确值的经度和纬度。

在我business_controller.rb我已经加入

def show 
    ... 
    @json = Business.find(params[:id]).to_gmaps4rails 
    ... 
end 

而且我已经加入

业务展示页面
%div 
    = gmaps4rails(@json) 

页脚包含

%footer 
    = yield :scripts 

现在看来谷歌地图的框架但它是空的。以下是有关该错误的相关线路:

<footer> 
225 <script type="text/javascript" src="//maps.google.com/maps/api/js?v=3.5&sensor=false&amp;libraries=geometry"></script> 
226 <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js"></script> 
227 <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.5/src/markerclusterer_packed.js"></script> 
228 <script type="text/javascript" src="//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js"></script> 
229 
230 <script type="text/javascript" charset="utf-8"> 
231 
232 Gmaps.map = new Gmaps4RailsGoogle(); 
233 Gmaps.load_map = function() { 
234 Gmaps.map.map_options.auto_adjust = true; 
235 Gmaps.map.initialize(); 
236 Gmaps.map.markers = [{"lng": "77.225", "lat": "28.6353"}]; 
237 Gmaps.map.markers_conf.do_clustering = true; 
238 Gmaps.map.create_markers(); 
239 Gmaps.map.adjustMapToBounds(); 
240 Gmaps.map.callback(); 
241 }; 
242 window.onload = function() { Gmaps.loadMaps(); }; 

的错误,现在是:

Gmaps is not defined" for line 232 

有谁知道它是什么呢?我也安装了geocoder,但我希望这不会产生任何问题。

谢谢!

+0

有地理编码和gmaps4rails之间没有冲突。这里的问题很奇怪。 – apneadiving

+1

'application31.js'应该是什么?它是由标准的'application.js'加载的吗? – apneadiving

+0

你可能只是缺少一些JavaScript包含某处。你有没有在模板中包含你的application-js? – phoet

回答

2

按我的意见,重新命名application31.jsapplication.js

相关问题