我在索引#操作中使用轨道project_site
中的.each
,每行显示基础模型,但
问题是模型展示在每个模型展示中只显示最后一个project_site
的id。我想要揭示应该揭示当前project_site
的id。
<% @project.project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
<tr>
<td><%= project_site.user.name %></td>
<td>
<div class="full reveal" id="exampleModal1" data-reveal>
<%= project_site.id %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<p><button class="button small warning button-margin-top fi-eye" data-open="exampleModal1"> View</button></p>
</td>
</tr>
<% end %>
每个模态都有相同的id,所以最后一个总是获胜。更改视图,使每行的模态都有自己的id,打开按钮调用正确的id。。。
<% @project.project_sites.where(submission_status: true).order("created_at desc").each do |project_site| %>
<tr>
<td><%= project_site.user.name %></td>
<td>
<% site_modal_id = "site_modal_#{project_site.id}" %>
<div class="full reveal" id="<%= site_modal_id %>" data-reveal>
<%= project_site.id %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
<p><button class="button small warning button-margin-top fi-eye" data-open="<%= site_modal_id %>"> View</button></p>
</td>
</tr>
<% end %>
请注意,如果你有很多项目网站,你的页面会变慢,最好有一个单一的模式,在cick上传递数据。