Reputation: 1
I have a question with this code. In this view I iterate over an array but I want to have the option to delete an entry from the array. Here is my code
<table>
<tr>
<th>Ware</th>
<th>Anzahl</th>
<th>Einzelpreis</th>
<th>Gesamtpreis</th>
</tr>
<% counter = 0 %>
<% $itemarray.each do |iarray| %>
<tr>
<% @items.each do |item| %>
<% if iarray.to_i == item.id %>
<th> <%= item.name %> </th>
<th> <%= $anzahlarray[counter] %> </th>
<th> <%= item.price.round(2) %> € </th>
<% preistemp = preistemp = item.price * $anzahlarray[counter].to_f %>
<th> <%= preistemp.round(2) %> € </th>
<th> <%= link_to 'Show', item_path(item) %> </th>
<th> <%= link_to 'Destroy', :hidden_param => 'counter' , method: :deleteshoppingcartentry(counter), data: {confirm: 'Are you sure?' }%></th>
<% end %>
<% end %>
</tr>
<% counter += 1 %>
<% end %>
</table>
def deleteshoppingcartentry
$itemarray.delete_at($entrynumber)
$anzahlarray.delete_at($entrynumber)
redirect_to "/orders/new"
end
maybe you could help me out
Upvotes: 0
Views: 87
Reputation:
You can't delete items from a global array variable. Use a database instead. Learn more about Rails' ActiveRecord.
Upvotes: 1