Provisioning 1 of 1 machines with image flyio/postgres:14.4
cart has many cart_item dependent: :destroy
<strong>Total price </strong> <%= order.cart_items.sum(&:total_price) %>
class OrdersController < ApplicationController def create @order = Order.new(order_params) current_cart.cart_items.each do |item| @order.cart_items << item end @order.user = current_user @order.saveCart.destroy(session[:cart_id]) session.delete(:cart_id)redirect_to orders_path, notice: "Thank you for your order" end private def set_order @order = Order.find(params[:id]) end def order_params params.require(:order).permit(:pay_method) end end