This repository was archived by the owner on Jul 24, 2020. It is now read-only.
This repository was archived by the owner on Jul 24, 2020. It is now read-only.
Unable to render cart if Equipment Models in cart destroyed no longer in DB #1085
Closed
Description
Steps to replicate:
- Seed DB
- Add item to cart (e.g.
cart.items[n] = 1
) - Destroy the relevant EquipmentModel (e.g.
EquipmentModel.find(n).destroy(:force)
) - Try to render catalog
The issue is that we're trying to render a link to remove an item from the cart but that item doesn't exist so link_to
is throwing an exception. I'd recommend we simply check for this case in the cart
method and remove items from the hash if necessary before passing it over to the view, e.g.:
def cart
...
session[:cart].items.each do |key, count|
session[:cart].items.delete(key) unless EquipmentModel.find_by_id(key)
end
...
Something like that, anyway.
Activity