I'm new to web programming and rails and I have the following question:
I have a view that displays a list of foods and a field to fill with the amount of grams I want from each food. I would like to display a text_field_tag
for each element of the list I have, something like:
<% @alimentos.each do |alimento| %>
<%= text_field_tag :alimento %>
<%= label_tag(:alimento, "#{alimento.nome}: #{alimento.preco} reais a grama" )%>
<% end %>'
However, I would like to send the amount I put in the fields for a javascript function that would multiply the price by the value I entered and then display the calculated total value in the view.
Unfortunately I have no idea how to do this: How do I create a text_field_tag
with a different symbol for each iteration of each ? How to send the values that fill the fields to the javascript function, where to create the javascript function and how to display the result of the function calculation?
Could anyone help me?