Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 在rails 4+;gmaps4rails 2.0.3_Ruby On Rails 4_Gmaps4rails2 - Fatal编程技术网

Ruby on rails 4 在rails 4+;gmaps4rails 2.0.3

Ruby on rails 4 在rails 4+;gmaps4rails 2.0.3,ruby-on-rails-4,gmaps4rails2,Ruby On Rails 4,Gmaps4rails2,Gmaps4rails未在rails 4.0.0中定义 谷歌Rails地图 我正在学习此教程“” 1)文件 gem'gmaps4rails' 2) 查看页面上的HTML 3) 在查看页面上 您也需要下划线.js,请参见此处:parendarejs.org/ 3) Javascript源代码 如果您有资产管道,请添加以下内容: //=需要下划线 //=需要GMAP/谷歌 如果没有资产管道,则需要导入js或coffee文件: rails g gmaps4rails:copy_js rails g g

Gmaps4rails未在rails 4.0.0中定义 谷歌Rails地图 我正在学习此教程“”

1)文件
gem'gmaps4rails'
2) 查看页面上的HTML
3) 在查看页面上
您也需要下划线.js,请参见此处:parendarejs.org/
3) Javascript源代码
如果您有资产管道,请添加以下内容:
//=需要下划线
//=需要GMAP/谷歌
如果没有资产管道,则需要导入js或coffee文件:
rails g gmaps4rails:copy_js
rails g gmaps4rails:复制
4) Javascript代码:
创建地图:
handler=Gmaps.build('Google');
buildMap({provider:{},internal:{id:'map'}},function(){
markers=handler.addMarkers([
{
“lat”:0,
“液化天然气”:0,
“图片”:{
“url”:”https://addons.cdn.mozilla.net/img/uploads/addon_icons/13/13028-64.png",
“宽度”:36,
“高度”:36
},
“信息窗口”:“你好!”
}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
但当我在firebug上查看时,它显示“GMAP未定义”” Ruby 2.0.0 rails 4.0.0 gmaps4rails 2.0.3


任何建议请回复……

我遇到了这个问题。问题是,在加载核心gmaps javascript之前,我在视图中加载了地图构建javascript

您可以通过在javascripts之后添加一个yield来解决这个问题,并使用content_for block将地图构建javascript放在其他javascript之后。大概是这样的:

<script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>    
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>  
<%= yield :javascripts %>

正确%>
然后,无论你在哪里绘制地图

<% content_for :javascripts do %>
<script type='text/javascript'>
    handler = Gmaps.build('Google');
    /* rest of maps building JS */
</script>
<% end %>

handler=Gmaps.build('Google');
/*地图建筑的其余部分*/

在rails 3上尝试了相同的步骤,但不起作用。我宁愿从头开始写JS,而不是浪费时间使用这个Gem。这似乎并没有解决问题@帕斯有什么突破吗?
<% content_for :javascripts do %>
<script type='text/javascript'>
    handler = Gmaps.build('Google');
    /* rest of maps building JS */
</script>
<% end %>