The following array ["2", "8", "134", "137", "140"] is generated via user input. The controller action invokes the arrays as follows:
params[:product_ids].each do |product_id|
@product = Product.where('id = ?', product_id).first
end
Unfortunately when calling the values in the view (for development control purposes)
<% params[:product_ids].each do |t| %>
<%= t %> <%= @product.id %><br />
<% end %>
is rendering the proper value for t but is then associating it with 140 five times.
2 140
8 140
134 140
137 140
140 140
thus accessing the LAST item of the array and ignoring the key. When this is attempted in the controller:
params[:product_ids].each do |k, product_id|
it is returning Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
How can the controller be defined to appropriately access the parameter's value?