Greetings! I have a sales form, in which I need that when writing the product code within its corresponding field, the fields, name and price, are automatically completed with the corresponding information that is in the database, and that they belong to that code, but to be honest, I'm not sure how to achieve it, I know you would have to achieve more with the part of js, I appreciate your help, this would be the form and my migration:
product_form.html.erb
<%= form_with(model: product, local: true) do |form| %>
<div class="field">
<%= form.label :code %>
<%= form.text_field :code %>
</div>
<div class="field">
<%= form.label :name %>
<%= form.text_field :name %>
</div>
<div class="field">
<%= form.label :price %>
<%= form.text_field :price %>
</div>
<div class="actions">
<%= form.submit %>
</div>
<% end %>
Product.rb
class CreateProducts < ActiveRecord::Migration[5.2]
def change
create_table :products do |t|
t.string :code
t.string :name
t.float :price
t.timestamps
end
end
end
I appreciate immensely someone could get me out of this quagmire!