Ruby on rails 内容中的脚本块用于:in脚本不';行不通
脚本块以Ruby on rails 内容中的脚本块用于:in脚本不';行不通,ruby-on-rails,Ruby On Rails,脚本块以$('#map#{shop.id}')开头…incontent\u for:in\u脚本不起作用 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? conte
$('#map#{shop.id}')开头…
incontent\u for:in\u脚本
不起作用
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
最终结果是如果shop.geocoded
为true
,则上面的脚本代码将在我的视图中显示为内联脚本:
<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 });
});
$(文档).ready(函数(){
$('#map1').gMap({标记:[{纬度:-1.030503,
经度:1.340594,
html:“\u latlng”},
{地址:'200 Good Street,加利福尼亚州,美利坚合众国',
html:“加州餐厅
”,
],
缩放:16});
});
谢谢。
的内容\u不输出任何内容,而是将HTML存储在缓冲区中,以便在其他位置(如页面的页眉或页脚)使用
在您看来或部分:
content_for :my_script do
"abc"
end
然后在布局中:
yield :my_script
如果没有yield
,您的内容将无法显示。您真正想要的是什么?我们不能在不知道该怎么做的情况下修复代码。对不起,我已经编辑了这篇文章,并让它更清晰。由于你的文章中没有问题,所以仍然不清楚你想要什么。在“content\u for:in\u script do”中的脚本块不起作用。也许你需要退出javascript?
yield :my_script