1

我在 index#action 中使用.eachRails project_site,每行显示基础模型,但是

问题是模型显示只显示project_site每个模型显示中最后一个的 id。我想显示应该显示当前的 id project_site

<% @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">&times;</span>
              </button>
           </div>

            <p><button class="button small warning button-margin-top fi-eye" data-open="exampleModal1"> View</button></p>


        </td>
  </tr>

<% end %>
4

1 回答 1

1

每个模态都有相同的 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">&times;</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 上传递数据。

于 2020-08-10T16:35:46.590 回答