How to call a ruby method when :onchange event is triggered (ruby on rails 4)?
<p>I am pretty new to ruby on rails...
On my <code>_form.html.erb</code> I have a <code>collection_select</code> field, which is populated from a Model called Product. The Product's table columns are <code>id, name, and price</code>. Once I select an item (product) from the collection I would like to populate a text field with the price of the selected product.</p>

<p>So far I have the following code IOT trigger an event when selecting an item:</p>

<pre><code>&lt;%= collection_select( :warehouse, :product_id, Product.all, :id, :name, {}, {:onchange =&gt; "alert('Hello World');"} )%&gt;
</code></pre>

<p>How can I call a ruby method which would let me populate the text_field with the corresponding price for the selected product?</p>

<p>For the method I was thinking something like...</p>

<pre><code>def set_price
      @price = Product.find(params[:id]).price
end
</code></pre>