1

I have this form in my view:

<%= form_tag({:action => :update_quantity}, :params => [:ids_to_update]) do %>
<% @id_array = [] %>
<% @db_lines.each do |line| %>
<% @id_array << line['id'] %>
    <tr>
      <td><%= image_tag "#{line['preview_url']}&maxSize=135" %></td>
      <td><%= line['ProductCode'] %></td>
      <td><%= text_field_tag("updated_quantity#{line['id']}", "#{line['Quantity']}") %></td>
      <td><%= number_to_currency(line['UnitPrice']) %></td>
      <td><%= number_to_currency(line['Quantity'] * line['UnitPrice']) %>
    </tr>
<% end %>
    <tr>
    <td colspan="5" class="text-right">
    <%= hidden_field_tag :ids_to_update, @id_array.join(',') %>
    <%= submit_tag("Update Quantity", :class => 'tiny button raidus') %>
    </td>
    </tr>
<% end %>

In the text_field_tag i'm setting each name to be updated_quantityx where x is the ID of the record. How do I pass each one of those into the params section of the form_tag when I don't know what the ID will be and how many will be there? The records are coming from my order_line model and this page is a separate controller for the shopping cart..

1 Answer 1

2

You don't need the params section in the form_tag. Params will be automatically generated by _tags inside the form.

The text_field_tag values will be passed to the controller as params[:updated_quantity#1], params[:updated_quantity#2] and so on.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.