Complete novice here. I have a line_item that once created or updated
calculates the capacity left and displays it in the events view. The
Add to Cart button triggers the create line_item method. I've added
further capacity calculations to the line_item destroy method. My
problem is that the line_item destroy method is not called when the cart
class Cart < ActiveRecord::Base
has_many :line_items, :dependent => :destroy
The line items are destroyed but the functionality in the line_item
destroy method does not run.
Line Item Controller ----
@line_item = LineItem.find(params[:id])
event = @line_item.event
new_quantity = params[:line_item_quantity].to_i
change_in_capacity = @line_item.quantity + new_quantity
respond_to do |format|
event.capacity = change_in_capacity
So I tried to add a call to it in the Cart Controller as follows ----
@cart = Cart.find(params[:id])
@line_item = LineItem.find(params[:cart_id])
session[:cart_id] = nil
but I can't seem to find the line item this way
"Couldn't find LineItem without an ID"
Any ideas? Thanks in advance from a complete beginner.