I have been trying to change my loop to decrement rather than increment. Nothing I have tried is working, please can someone help me.
<% @orders.each do |order| %>
#code
<% end %>
Thanks
Same as Array#each, but traverses self in reverse order.
try the below :
<% @orders.reverse_each do |order| %>
#code
<% end %>
@orders.reverse.each as well, in case someone considered that. At least on MRI, reverse_each is implemented as a loop that counts from the end of the array to the beginning, while reverse.each creates a new array and then loops over that (so, reverse_each is roughly O(n), while reverse.each is roughly O(2n) (disclaimer: I don't actually know big O notation, so this may be completely wrong)).
eachdoes. It traverses the contents of your@ordersarray, from the first element to the last. To walk that list backwards you have to reverse the list somehow. The Array documentation covers that nicely.