1

i am using .each in rails project_site in index#action with foundation model reveal on each row but

issue is model reveal just shows id of last project_site in each model-reveal. i want reveal should reveal id of current 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 %>
rock
  • 348
  • 4
  • 18
  • @dbugger this was typo error in question. issue is still same last ```project_site``` id gets pritned on each model reveal – rock Aug 10 '20 at 16:04

1 Answers1

1

Each modal has the same id, so the last one always wins. Change the view so each row's modal has its own id, and the open button calls the proper one...

<% @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 %>

Note that if you have a lot of project sites your page is going to slow down and it would be better to have a single modal where you pass in the data on the cick.

dbugger
  • 15,868
  • 9
  • 31
  • 33
  • can i do this by ajax call for a lot project_site or it possible to render a page on model reveal – rock Aug 11 '20 at 04:43
  • It's up to you. You can redirect to a full page, open a modal directly as you are doing or via ajax. – dbugger Aug 11 '20 at 12:42