1
私はビューページでタグを使用しますが、地図が表示され、ファイルはうまく動作します。 app/assets/javascriptsフォルダにスクリプトを配置して呼び出すと、マップまたは実行スクリプトが表示されません。これは私が持っているものです。何か案は?ありがとうございました。Rails 5.1.4にJSスクリプトが含まれています
のconfig/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));
}