助手中的这段代码:
def dgtags
if params[:controller]=='my_controller'
javascript_include_tag('dygraph-combined.js') <<
tag(:meta, :http_equiv => 'X-UA-Compatible', :content => 'IE=EmulateIE7; IE=EmulateIE9') <<
'<!--[if IE]>'.html_safe <<
javascript_include_tag('excanvas.compiled.js') <<
'<![endif]-->'.html_safe
end
end
产生以下输出:
<script src="/javascripts/dygraph-combined.js?1338036501" type="text/javascript"></script><meta content="IE=EmulateIE7; IE=EmulateIE9" http_equiv="X-UA-Compatible" /><!--[if IE]><script src="/javascripts/excanvas.compiled.js?1237712986" type="text/javascript"></script><![endif]-->
如何在标签之间插入换行符?像这样:
<script src="/javascripts/dygraph-combined.js?1338036501" type="text/javascript"></script>
<meta content="IE=EmulateIE7; IE=EmulateIE9" http_equiv="X-UA-Compatible" />
<!--[if IE]><script src="/javascripts/excanvas.compiled.js?1237712986" type="text/javascript"></script><![endif]-->
'\n' 或 '\n'.html_safe 无济于事 - 它按字面意思生成 \n。