当我在视图页面上使用标签时,地图显示和文件运行正常。当我将脚本放在app / assets / javascripts文件夹中并调用它时,它不会显示地图或运行脚本。这就是我所拥有的。有任何想法吗?谢谢。
配置/ intializers / assets.rb:
Rails.application.config.assets.precompile += %w( mapshow.js )
app.assets /视图/位置/ map.html.erb
<%= javascript_include_tag 'mapshow' %>
资产/ Javascript角/ mapshow.js
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(37.725685, -122.156830),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var places = <%= @locations.to_json.html_safe %>
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < places.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(places[i].lat, places[i].lng),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(places[i].location_name + " <br /> " + places[i].location_description + " <br /> " + places[i].location_address);
infowindow.open(map, marker);
}
})(marker, i));
}
答案 0 :(得分:0)
javascript_include_tag
生成的行。复制地址并将其粘贴到地址栏中。检查文件是否已下载。.js.erb
扩展名的视图中,并使用XHR下载它们(您还需要为此定义新的控制器和路由)