2017-11-02 1 views
1

보기 내에서 content_for을 사용했습니다. 블록 youtube_explain의 콘텐츠를 표시하지 않는 것보기 내에서 'content_for'사용

<div class="row"> 
    <div class="col-lg-12"> 
    <div class="panel panel-default"> 
     <%= content_for :youtube_explain %> 
    </div> 
    </div> 
</div> 

<% content_for :youtube_explain do %> 
    <div> 
    物件 ⇒ <%= link_to "ント(編)", "https://youtu.be/ZYhR" %> 
    </div> 
<% end %> 

: 이것은 내 코드입니다.

+0

귀하의 코드가 올바른 것 같다 ([DOCS]에 따라 https://apidock.com/rails/ActionView/Helpers/CaptureHelper/content_for). 하지만, <% = content_for : youtube_explain %> 대신'<% = yield : youtube_explain %>'을 시도해 볼 수 있습니까 – Abhi

+0

의견으로'yield'를 사용하려했으나 표시되지 않았습니다. –

+0

@sawa 제 질문은 'content_for'안에 넣은 블록 html 코드가 표시되지 않았습니다. –

답변

1

당신처럼 그것을 호출하기 전에 마크 업의 당신의 블록을 정의해야합니다 그렇지 않으면

<%= content_for? :youtube_explain %> 

<% content_for :youtube_explain do %> 
    <div>物件 ⇒ <%= link_to "ント(編)", "https://youtu.be/ZYhR" %></div> 
<% end %> 

<!-- false --> 

:

<% content_for :youtube_explain do %> 
    <div>物件 ⇒ <%= link_to "ント(編)", "https://youtu.be/ZYhR" %></div> 
<% end %> 

<%= content_for? :youtube_explain %> 

<!-- true --> 
관련 문제