The script block begins with $('#map#{shop.id}').....
in content_for :in_script
doesn't work.
def edit_country_fields_template(city, shop)
content_tag(:div, :class => "item") do
"<div id='map#{shop.id}' class='map'></div>".html_safe +
if shop.geocoded?
content_for :in_script do
$('#map#{shop.id}').gMap({ markers: [{ latitude: #{spot.lat},
longitude: #{shop.lng},
html: '_latlng' },
{ address: '#{shop.address_geo}',
html: '#{shop.name}<br/><a href='http://maps.google.com/maps?q=#{shop.address_geo}' target='_blank'>See Full Map</a>' },
],
zoom: 16 });
end
end
end
end
I have this helper called in my view edit.html.erb
with <%= edit_country_fields_template %>
. But I have problem having the script code below added inline in the script of the view file:
$('#map#{shop.id}').gMap({ markers: [{ latitude: #{spot.lat},
longitude: #{shop.lng},
html: '_latlng' },
{ address: '#{shop.address_geo}',
html: '#{shop.name}<br/><a href='http://maps.google.com/maps?q=#{shop.address_geo}' target='_blank'>See Full Map</a>' },
],
zoom: 16 });
The end result is if shop.geocoded
is true
, the script code above will be shown in my view as inline script:
<script type="text/javascript">
$(document).ready(function(){
$('#map1').gMap({ markers: [{ latitude: -1.030503,
longitude: 1.340594,
html: '_latlng' },
{ address: '200 Good Street, California, United States of America',
html: 'California Restaurant<br/><a href='http://maps.google.com/maps?q=200 Good Street, California, United States of America' target='_blank'>See Full Map</a>' },
],
zoom: 16 });
});
Thanks.