Setting up Leaflet with Ruby on Rails -
i attempting leaflet setup in rails application properly, , having trouble. following steps outlined here github leaflet repo. have done trivial stuff @ top , under headers heading.
i using openstreetmaps, leaflet.rb file looks this. (i had create file myself did not exist)
leaflet.tile_layer = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' leaflet.attribution = '© <a href="http://openstreetmap.org">openstreetmap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">cc-by-sa</a>' leaflet.max_zoom = 18
now view trying insert leaflet map in looks this.
<% provide(:title, 'map') %> <h1>map</h1> <div id="map"><% map(:center => { :latlng => [51.52238797921441, -0.08366235665359283], :zoom => 18 }) %> </div> <p>find me in app/views/dynamic_pages/map.html.erb</p>
when fire rails server, there empty space in div i.e. no map. div setup height of 500px in css file if makes difference, don't think does.
what doing wrong here?
i'm sure figured out now... in case else stuck. leaflet-rails documentation leaves out details on how happens, map helper is available in views. must in <%= %>
tags display; problem above erb tag missing =
should this,
<div id="map"> <%= map(:center => { :latlng => [51.52238797921441, -0.08366235665359283], :zoom => 18 }) %> </div>
as side note, =
in erb tag tells interpreter following code expression meant returned string document. erb tage without =
<% %>
evaluate code, not try return it. more see this blog post more.
Comments
Post a Comment