2013-03-12 2 views
0

렌더링에 특정 매개 변수 "has_footer"가 포함되어 있으면 부분적으로 부분을 렌더링하려고합니다. _modal.html.erb에서Rails : 매개 변수가있는 경우 부분 컨텐트 렌더링

, 나는 다음과 같습니다

<div id="<%= id %>" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true"> 
    <div class="modal-header"> 
    <button type="button" class="btn-modal-close" data-dismiss="modal" aria-hidden="true">×</button> 
    <header><%= title %></header> 
    </div> 
    <div class="modal-body"> 
    <%= render partial: content %> 
    </div> 
    <% if params[:has_footer] %> 
    <div class="modal-footer"> 
     <button class="btn-modal-save">Save</button> 
     <button class="btn-modal-cancel" data-dismiss="modal" aria-hidden="true">Cancel</button> 
    </div> 
    <% end %> 
</div> 

그리고 나는 부분과 같이 렌더링 :

<%= render "pages/modal", :has_footer, id: "modal-add-campaign", title: "Add Campaign", content: "pages/modal_add_campaign" %> 

는 기본적으로,이 사업부를 표시하려면 "모달 - 바닥 글 "내 렌더링 명령에": has_footer "매개 변수를 포함해야만 가능합니다.

도움이 필요하십니까?

답변

1

부분 변수에 전달 된 변수는 지역 변수처럼 취급됩니다. 그래서 나는 같은 것을 할 것 :

<%= render :partial => "pages/modal", locals: { has_footer: true, id: "modal-add-campaign", title: "Add Campaign", content: "pages/modal_add_campaign" } %> 

을 그리고이 같은 변수를 확인하십시오

if has_footer 
+0

감사합니다! 이것은 항상 "has_footer : false"또는 "has_footer : true"중 하나를 정의해야한다는 것을 의미합니다. 필요한 경우 "true"로 기본 설정하고 "false"로만 전달할 수 있습니까? – Gabriel

관련 문제