title: duplicate result on change event in forms_for block
body: <p>I am new to Rails.</p>
  
  <p>I have nested form. </p>
  
  <pre><code>&lt;div id="items"&gt;
    &lt;%= f.simple_fields_for :items do |i| %&gt;
        &lt;%= render 'item_fields', :f =&gt; i %&gt;
    &lt;% end %&gt;
    &lt;div class="links"&gt;
      &lt;%= link_to_add_association '+ produk', f, :items %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>item_fields:</p>
  
  <pre><code>&lt;%= f.select :product_id, Product.all.collect {|p| [p.name, p.id, {'data-unit_cost'=&gt;p.sell_price }]}, { class: 'product-select'} %&gt;
  &lt;%= f.input :qty %&gt;
  &lt;%= f.input :unit_cost%&gt;
  &lt;%= f.input :discount %&gt;
  &lt;%= f.number_field :subtotal %&gt;
  </code></pre>
  
  <p>script:</p>
  
  <pre><code>$(".product-select").change -&gt;
    unit_cost = $('.product-select :selected').data('unit_cost') or 0
  </code></pre>
  
  <p>The idea is whenever product_id is selected, it will set the value of unit_cost.
  The thing is, it works only for the first row of the nested form, the second one and next, the value will be duplicated of the first row.</p>
  
  <p>Any help would be appreciated.</p>