title: Get other field form selected item rails
body: <p>I am making rails app like this.</p>
  
  <pre><code>#Gemfile
  gem 'cocoon'
  gem 'haml-rails'
  gem 'simple_form'
  
  rails g scaffold order total_price
  rails g scaffold product product_name product_price:integer
  rails g model order_detail quantity:integer unit_price:integer subtotal_price:integer order:references product:references
  
  
  class Order &lt; ApplicationRecord
    has_many :order_details
    has_many :products, through: :order_details
  
    accepts_nested_attributes_for :order_details, :reject_if =&gt; :all_blank, :allow_destroy =&gt; true
  end
  
  class Product &lt; ApplicationRecord
     has_many :order
  end
  
  class order_detail &lt; ApplicationRecord
    belongs_to :order
    belongs_to :product
  end
  </code></pre>
  
  <p>When user make order, use this form,</p>
  
  <pre><code>#app/views/order/_form.html.haml
  = simple_form_for (@order) do |f|
    #order_details
    = f.simple_fields_for :order_details do |order_detail|
      = render 'order_detail_fields', f: order_detail
    .links.text-right
      = link_to_add_association 'add product', f, :order_details
    = f.input :total_price, disabled: true
  
    .form-actions
      = f.button :submit
  
  #_order_detail_fields.html.haml
  .row.nested-fields
    .col-sm-3
      = f.association :product, :label_method =&gt; :name
    .col-sm-1
      = f.input :quantity
    .col-sm-2
      = f.input :unit_price
    .col-sm-2
      = f.input :subtotal_price, disabled: true
    .col-sm-2
      = link_to_remove_association "remove", f
  </code></pre>
  
  <p>So I want to know when user select product, how to put the product_price of product selected into unit_price of order_detail.</p>
  
  <p>I have tried to use ajax or json, but it doesn't work well. If somebody has a good advise or knows good sample, please tell me.</p>
  
  <p>And if it can be calculated quantity * unit_price, when product selected, I can make better.</p>