2017-03-16 5 views
1

내 컨트롤러에서 기본 케이스를 설명하기 위해 HTML 문자열과 동일한 변수를 설정합니다. 그러나 #은 나머지 줄을 주석 처리합니다. 이걸 어떻게 피할 수 있니?Rails # in href html 주석 외 라인

@chart_data = "<p id='chart-notice'>If you <a href="#SOME_ID">login to your social media apps</a>, this section will display social analytics.</p>" 

참고 : 이것은에이 .rb

답변

3
@chart_data = <<-HTML.strip! 
    <p id='chart-notice'>If you <a href="#SOME_ID">login to your social media apps</a>, this section will display social analytics.</p> 
HTML 

또는

@chart_data = %Q{ 
    <p id='chart-notice'>If you <a href="#SOME_ID">login to your social media apps</a>, this section will display social analytics.</p> 
}.strip! 

또는

@chart_data = "<p id='chart-notice'>If you <a href=\"#SOME_ID\">login to your social media apps</a>, this section will display social analytics.</p>" 

에주의 인 .html.erb 파일이 아닙니다 다음 코드

+0

따옴표의 두 가지 유형을 사용하는 경우, '%의 Q'는 가장 지저분한 솔루션입니다. '<<'는 여러 줄 문자열에도 잘 맞는 HEREDOC 스타일입니다. – tadman

0

봅니다 :

@chart_data = "<p id='chart-notice'>If you <a href='#SOME_ID'>login to your social media apps</a>, this section will display social analytics.</p>"