title: Ruby on Rails - Show the same modal with different content
body: <p>I have a home page with a list of software in a table.</p>
  
  <p>With this link I open my softwares pages in modals:</p>
  
  <pre><code>&lt;% = link_to software_path (software), remote: true do %&gt; ... &lt;% end%&gt;
  </code></pre>
  
  <p>I created a script allowing me to open my modals when I click on td with class <code>.clickable</code> and not open modals when I click on a td with class <code>.no-click</code>.</p>
  
  <pre><code>$(".clickable").click(function(e) {
    if (!$(e.target).hasClass('no-click')) {
        $('#software-modal').modal('show');
      }
  });
  </code></pre>
  
  <p>structure :</p>
  
  <p>_software.html.erb open _software_modal.html.erb</p>
  
  <p>Problem:
  When I try to open my modals via the script, it's always the same modal that opens. That is, the modal of software 1 opens when I click on software 2, software 3, ... but no problem when I just use the link.</p>
  
  <p>So I have a problem with id or something like that in my script ...</p>
  
  <p>Can you help me ?</p>
  
  <blockquote>
    <p><strong>EDIT 1:</strong>  With the response of VAD I tried to search the id with data-id.</p>
  </blockquote>
  
  <p>_software.html.erb</p>
  
  <pre><code>&lt;tr class="clickable" data-id="&lt;%= software.id %&gt;"&gt;
  ...
  &lt;/tr&gt;
  &lt;div id='software-content'&gt;&lt;/div&gt;
  </code></pre>
  
  <p>_software_modal.html.erb</p>
  
  <pre><code>&lt;div id="software-modal" class="modal fade" role="dialog"&gt;
  ...
  &lt;/div&gt;
  </code></pre>
  
  <p>show.js.erb</p>
  
  <pre><code>$('#software-content').html("&lt;%= j render 'software_modal', software: @software %&gt;");
  $('#software-modal').modal('show');
  </code></pre>
  
  <p>this show.js.erb allows me to open my modals via example links:</p>
  
  <pre><code>&lt;%= link_to software.name, software_path(software), remote: true,class:"no-click" %&gt;
  </code></pre>
  
  <p>but not via a clickable table.</p>
  
  <p>So I added a script in _software.html.erb that makes my table clickable:</p>
  
  <pre><code>  $(".clickable[data-id]").click(function(e) {
      if (!$(e.target).hasClass('no-click')) {
        window.location = '/softwares/' + $(this).attr('data-id');
      }
  });
  </code></pre>
  
  <p>I also tried with data-link, ... is there a way to open this window.location in a modal (like the link)? I searched for several hours yesterday but I did not find anything ..</p>
  
  <blockquote>
    <p><strong>EDIT 2</strong></p>
  </blockquote>
  
  <p>following the response of @VAD with render layout: false, we can put:</p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
     layout proc{|c| c.request.xhr? ? false : "application" }
  end
  </code></pre>
  
  <p>which allows to have a false render for the js and true render for html. And so to keep my html pages with my starting layout.</p>
  
  <p>Thx @dogenpunk 
  <a href="https://stackoverflow.com/questions/5729476/render-without-layout-when-format-is-js-needs-drying">Render without layout when format is JS (needs drying)</a></p>