Reputation: 323
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..
Upvotes: 1
Views: 909
Reputation: 3742
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.
Upvotes: 2