Skip to content
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
@orenyk

Description

@orenyk

Steps to replicate:

  1. Seed DB
  2. Add item to cart (e.g. cart.items[n] = 1)
  3. Destroy the relevant EquipmentModel (e.g. EquipmentModel.find(n).destroy(:force))
  4. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions