2012-05-26 4 views
0

사이에이 코드를 나누기 :레일 도우미 - 라인 도우미에 태그

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]--> 

어떻게 라인 태그 사이에 나누기 삽입? - 그것은 N \ 그대로 생산

<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 도움이되지 않습니다 : 이것처럼. 난 당신의 코드를 약간 변경 한 http://en.wikibooks.org/wiki/Ruby_Programming/Strings

:

답변

1

당신은 '\n'

당신은 여기에서 더 자세한 정보를 얻을 수 없습니다 따옴표"

사용 "\n"을 사용해야합니다. 더 나은 접근 방식은 을 사용하는 모든 요소가에 속하는 입니다. params[:controller] 대신 controller_name을 사용할 수도 있습니다.

def dgtags 
    if controller_name == 'my_controller' 
     [ javascript_include_tag('dygraph-combined.js'), 
     tag(:meta, :http_equiv => 'X-UA-Compatible', :content => 'IE=EmulateIE7; IE=EmulateIE9'), 
     '<!--[if IE]>', 
     javascript_include_tag('excanvas.compiled.js'), 
     '<![endif]-->'].join("\n").html_safe 
    end 
end 
+0

특히 예를 들어 주셔서 감사합니다. – Paul