Note that there are some explanatory texts on larger screens.

plurals
  1. POLeaflet: blank page after refresh
    primarykey
    data
    text
    <p>I am using leaflet.js in a Rails 4 application. I have a page called fields, where I show a map. The page displays well, but when I refresh it, the rendered result is a blank page.</p> <p>Here is my javascript code:</p> <pre><code># app/assets/javascript/fields.js.coffee $(document).ready -&gt; map = L.map('map') L.tileLayer("http://{s}.tile.cloudmade.com/my-API-KEY/997/256/{z}/{x}/{y}.png", { attribution: 'Map data &amp;copy; &lt;a href="http://openstreetmap.org"&gt;OpenStreetMap&lt;/a&gt; contributors, &lt;a href="http://creativecommons.org/licenses/by-sa/2.0/"&gt;CC-BY-SA&lt;/a&gt;, Imagery © &lt;a href="http://cloudmade.com"&gt;CloudMade&lt;/a&gt;', maxZoom: 18 }).addTo(map) bounds = new L.LatLngBounds for field in $(".field_in_map") $field = $(field) latlng = [$field.data("latitude"), $field.data("longitude")] bounds.extend(latlng) desc = $field.data("description") addr = $field.data("address") marker = L.marker(latlng).addTo(map) marker.bindPopup("&lt;a href=#{addr} data-no-turbolink&gt;&lt;b&gt;#{desc}&lt;/b&gt;&lt;/a&gt;&lt;br&gt;") map.fitBounds(bounds) if $(".field_in_map").length==1 &amp;&amp; $(".field_in_map").data("zoom") map.setZoom($(".field_in_map").data("zoom")) </code></pre> <p>My index page:</p> <pre><code># app/views/fields/index.html.erb … &lt;% @fields.each do |field| %&gt; &lt;%= content_tag :div, class: "field_in_map", data: { latitude: field.latitude, longitude: field.longitude, description: print_field(field), address: field_path(field) } do %&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;div id="map" class="map_with_all_fields"&gt;&lt;/div&gt; … </code></pre> <p>My gemfile:</p> <pre><code># Gemfile … gem 'leaflet-rails' … </code></pre> <p>In my configurations, I have <strong>config.assets.initialize_on_precompile = false</strong> and <strong>config.serve_static_assets = true</strong>.</p> <p>Before launching the server, I generate the assets:</p> <pre><code>$&gt; rake assets:precompile </code></pre> <p>Once the server is up, I visit the index page for fields and everything is ok. But once I press CMD+R (refresh), I have a blank page.</p> <p>Thank you for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload