没有在heroku上加载MapBox的地图

时间:2015-07-09 09:28:39

标签: ruby-on-rails heroku mapbox

我的heroku有问题。我的地图没有出现在制作中,但在开发中有效。

我在JS的地图:

var ready;
ready = function() {
    L.mapbox.accessToken = 'pk.eyJ1IjoiYmxhY2t5IiwiYSI6IjA4NWJjZDNiNDQ0MTg3YjVmZTNkM2NkMWQ3MmM4ZjU4In0.SDQh56AZPCbIL2rVs4eAkQ';
    $('.map').each(function() {
        var map = L.mapbox.map($(this).attr('id'), 'mapbox.streets').setView([48.855, 2.4], 8);

        var geocoder = L.mapbox.geocoder('mapbox.places');
        var adress = document.getElementById($(this).attr('id'));

        geocoder.query(adress.getAttribute("data-adress-map"), showMap);

        function showMap(err, data) {
            // The geocoder can return an area, like a city, or a
            // point, like an address. Here we handle both cases,
            // by fitting the map bounds to an area or zooming to a point.
            if (data.lbounds) {
                map.fitBounds(data.lbounds);
            } else if (data.latlng) {
                map.setView([data.latlng[0], data.latlng[1]], 13);
            }

            var marker = L.marker([data.latlng[0], data.latlng[1]]).addTo(map);

            marker.bindPopup(adress.getAttribute("data-title-map") +"<br>"+ adress.getAttribute("data-adress-map"));
        }

    })

};

$(document).ready(ready);
$(document).on('page:load', ready);

我的观点index.erb:

<div id="map-<%= page.position %>" class="map" data-title-map="<%= page.title_map %>" data-adress-map="<%= page.adress_map %>"></div>

app / views / layouts / application.html.erb:

  <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  <%= stylesheet_link_tag    'https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.css' %>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag  'https://api.tiles.mapbox.com/mapbox.js/v2.2.1/mapbox.js' %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
  <%= render 'layouts/ga' %>

一个想法?

感谢。

2 个答案:

答案 0 :(得分:1)

好吧,我找到了。

我在config / environments / production.rb中添加了这一行:

config.serve_static_assets = true

然后:

RAILS_ENV=production bundle exec rake assets:precompile

并且:

heroku run rake assets:precompile

感谢。

答案 1 :(得分:0)

config/environments/production.rb

中将config.assets.compress设置为true
config.assets.compress = true