title: Rails: file nested fields, show the name of file selected on each field
body: <p>I'm using the <code>cocoon gem</code> in order to add images with nested fields:</p>
  
  <pre><code>&lt;div id="attachments"&gt;
      &lt;%= f.simple_fields_for :attachments do |attachment| %&gt;
      &lt;%= render 'products/attachment_fields', form: attachment  %&gt;
      &lt;% end %&gt;
          &lt;div class="links" id="add_attachment" style="display: inline; float: right;"&gt;
             &lt;%= link_to_add_association 'add more images', f, :attachments, form_name: 'form' %&gt;
           &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And this is the partial.... _attachment_fileds.tml.erb:</p>
  
  <pre><code>&lt;div class="nested-fields"&gt;
    &lt;%= form.label :image, required: true %&gt;
      &lt;div class="input-group"&gt;
        &lt;div class="custom-file" style="padding-top: 38px;"&gt;
          &lt;%= form.input :images, label: false, as: :file, :input_html =&gt; { :class =&gt; 'custom-file-input', :style=&gt;"cursor: pointer", :id=&gt;"inputGroupFile01"} %&gt;
          &lt;label class="custom-file-label" for="inputGroupFile01" id="file-name" style="cursor: pointer;"&gt;Choose file&lt;/label&gt;
        &lt;/div&gt;
      &lt;/div&gt;
         &lt;div style="text-align: right;"&gt;&lt;%= link_to_remove_association "remove", form %&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Everything is working fine.</p>
  
  <p>Now, regarding each field that is generated with <code>cocoon</code> I would like to replace the <code>choose a file</code> text from the label field  with the name of the file that  has been selected. </p>
  
  <p>At first I tried the following but I then figured that the <code>cocoon gem</code> generates a different id for each field. </p>
  
  <pre><code>&lt;script&gt;
    $("#inputGroupFile01").change(function(){
        $("#file-name").text(this.files[0].name);
    });
  &lt;/script&gt;
  </code></pre>
  
  <p>So now I'm kind of stuck on how to implement the above. Any help would be very much appreciated.</p>