I have This in The Form
<%= simpleform_for @customer_bill do |f| %>
<%= f.label :product_id %>
<%= f.collection_select :product_id,Product.all,:id,:title, :prompt => "Select a Product", :style => 'width:150px;' %>
<%= f.label :price %>
<%= f.text_field :price, :size=>20, :id =>"price", :class =>"price" %>
<br/>
/*rest of code*/
In The Products Table I Have ‘Product title’ and ‘price’. And i have the necessary association made between customer bill and Products model.
Once the Product is selected Price should automatically come. WHich is the best way to do it?? Ajax/ Jquery How can i Proceed with the Problem???? Any Guidance would be helpful.
You can use data-xxx attribute of your select-tag to store prices and let javascript to handle it:
JavaScript:
Template (it’s Haml, but I guess you’ll get the idea even if you’re ERb-guy):
Note the using of
f.associationinsteadf.collection_select. I think in your case it’s simpler to use.