24 Oct 2013, 21:43
Generic-user-small

AC Motanya (2 posts)

undefined method `+’ for nil:NilClass

def add_product(product_id) current_item = line_items.find_by(product_id: product_id) if current_item current_item.quantity += 1 else current_item = line_items.build(product_id: product_id) end current_item end

something is wrong with this add method. Nothing I can do will make the line items add up in the cart.

24 Oct 2013, 21:59
Generic-user-small

AC Motanya (2 posts)

No one was going to answer this anyway, but just in case.. I figured it out.

17 Dec 2014, 08:26
Generic-user-small

Anfo Ochoa (2 posts)

AC Motanya how did you fixed this issue?

I can’t get the cart to add to the quantity.

Everytime I add a new product to the cart. It just keeps creating a new list_item instead of updating the quantity.

Any advice?

Thank you.

	def add_product(product_id)
		current_item = line_items.find_by(product_id: product_id)
		if current_item
			current_item.quantity += 1
		else
			current_item = line_items.build(product_id: product_id)
		end
		current_item
	end
17 Dec 2014, 08:32
Generic-user-small

Anfo Ochoa (2 posts)

Fixed. It worked after deleting the cache files in the tmp folder

  You must be logged in to comment