I am following this guide for creating a shopping cart model: https://richonrails.com/articles/building-a-shopping-cart-in-ruby-on-rails
I got it to work successfully, but still have a problem. When I load the page, and add an item, one is added, if I go to another page, and then load the home page again, through a side bar menu I have, I click a product, and that same product gets added 3 times to the shopping cart. I go to another page and return, 5 items per click, again 7 items per click. I have no idea why this is happening, I don't even know what part of my code to show, so someone can help me. If I reload the page (by clicking the address bar and enter), it goes back to adding one item per click.
Thanks in advance
EDIT: After first comment suggestion, here is the controller code.
def create
@invoice = current_invoice
@invoice_product = @invoice.invoice_products.new(invoice_product_params)
@invoice.save
session[:invoice_id] = @invoice.id
end
def update
@invoice = current_invoice
@invoice_product = @invoice.invoice_products.find(params[:id])
@invoice_product.update.attributes(order_item_params)
@invoice_products = @invoice.invoice_products
end
def destroy
@invoice = current_invoice
@invoice_product = @invoice.invoice_products.find(params[:id])
@invoice_product.destroy
@invoice_products = @invoice.invoice_products
end
private
def invoice_product_params
params.require(:invoice_product).permit(:id, :invoice_id, :product_id, :price, :tax, :value)
end