* Still need help on this. The duplicate that people have suggested does not answer my question. It answers one of my questions but not this one. I have taken a look at the duplicate that people have recommended and that certainly helped me, in that now I have some jQuery code that detects when the value changes and I can see the actual value, but how do I then set the value of the other field in jQuery (the price) since I need to call some SQL to find the price based upon the item ID that was changed right? So, how I get the price once I have the item id? The price is not a drop down, which is what is being suggested, it is simply a data entry field that I want to default once the item is picked. *
I am trying to work out how I can have a select on one field in rails, which returns a certain value into this field but also returns another value to another field.
For example, I want to select a certain item so the select shows the item name but returns the id into the underlying field value. That is fine, no problems with that. But, I also have a price field that I'd like to populate with the item price once the item is selected in field one. I don't think this is possible using the select helper in rails correct?
Is there a good way of doing this? I am still quite new to rails so please be gentle :)
Here is what I have, but it isn't working :(
<%= f.select :id, Item.where('id = ?', ":item_id").order('price ASC').all.map {|ref| [ref.price, ref.id]}, { include_blank: false, required: true} %>
:item_id is in the previous field and is also chosen from a select.