How do I exclude the first and/or last item in the Rails each:
<% @shops.each_with_index do |shop, i| %>
... some code ...
<% end %>
Use a range to slice the array before invoking each_with_index:
If you want to exclude the first element, start from 1.
To exclude the last element, end at -2.
@shops[1..-2].each_with_index do |shop, i|
...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With