나는 has_many :comments
인 post
모델을 가지고 있습니다. 각 댓글 (_comment.html.erb
부분으로 생성 됨)에 대해 별표가 표시되도록 별표 아이콘이 있습니다.여러 번 렌더링되는 부분에 대해 하나의 html 코드를 갖는 방법
사용자가 별을 클릭 할 때 모달 폼 (부트 스트랩)을 열고 싶습니다.
모달을 만드는 방법을 알고 있습니다. 그러나 코드를 _comment
부분에 넣으면 각 주석에 대해 렌더링됩니다.
거기에 javascript없이 각 댓글에 대한 모달 창을 여는 방법이 있습니까 (아니면 그 유일한 방법일까요?).
_comment :
<div id="comment-#{comment.id}>
<%= comment.content %>
<a href="#starModal" id="star" data-toggle="modal"><i class="icon-star"> </i></a>
</div>
<div id="starModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="starLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 style="text-align: center;">Star Me!</h3>
</div>
<div id="starpop">
<%= render :partial => 'layouts/star_form' , :locals => {:comment => comment,:post => post} %>
</div>
</div>
포스트/show.html.erb
<div class="post">
<%= @post.body %>
<% @post.comments.each do |c| %>
<%= render :partial=>'comment', :locals=>{:comment => c, :post => @post} %>
<% end %>
</div>
는 모달 코드를 올바른 접근 방식을 가지고있다되거나 무거운되지도 건조 방법 개선 (될 수 있습니다 사용자는 페이지에 수백 개의 댓글이 있습니다. 각 댓글에 모델에 대한 데이터가 두 배가되도록 하시겠습니까?)
그래서 각 메모가 자신의 모달 div를로드하지 않도록 하시겠습니까? –
yup- @ rails_has_elegance는 내가 피하고 싶은 바로 그 것입니다. 주로 내가 모달 코드와 함께 부풀려지기 위해 게시 #하지 않기 때문에 –