Im comparing model products with API contain the same data and print a table. The code printing the same results with same Id and out of order.
<% @resultsApiCode.each do |search| %>
<% @products.each do |product| %>
<td>
<p ><%= search['id']%></p>
</td>
<td>
<p ><%= search['rfidCode']%></p>
</td>
<td>
<p ><%= search['created_at']%></p>
</td>
<td>
<%if(product.rfid).eql? (search['rfidCode']) %>
<td >
<%= link_to product_path(product), class:"btn btn-info"%>
</td>
<%else%>
<td >
<%= link_to new_product_path, class:"btn btn-success"%>
</td>
<%end%>
<%end%>
<%end%>
Exemple:
698 302EF13EFDD0F24000000001 2022-01-20T19:45:14.345Z
698 302EF13EFDD0F24000000001 2022-01-20T19:45:14.345Z
698 302EF13EFDD0F24000000001 2022-01-20T19:45:14.345Z
698 302EF13EFDD0F24000000001 2022-01-20T19:45:14.345Z
698 302EF13EFDD0F24000000001 2022-01-20T19:45:14.345Z
...
CodePudding user response:
Looks like the results you want to show are in @resultsApiCode but then you loop over @products for each result, so basically if you have N products you will see the same line several times.
CodePudding user response:
Exactly, i using the method GET tô search API the results @resultsApiCode. I need compare all results @products.rfid with search['rfidCode'] and show in the view results If exists in my database or no exists.But in my code not working.
