app/controllers/orders_controller.rb
# POST orders/
# Function to insert new item into cart. Must
# have proper post values.
POST orders
Function to insert new item into cart. Must
have proper post values.
POST orders Function to insert new item into cart . Must have proper post values .
def create()
    params = create_params
    @insert_cart = Cart.where(:user_id => current_user.id, :product_id => params["product_id"]).first
    if !@insert_cart.nil?
      @insert_cart.quantity = Integer(@insert_cart.quantity) + Integer(params["quantity"])
    else
      @insert_cart = Cart.new(params)
    end
    if @insert_cart.save
      redirect_to "/browse", flash: {notice: "Cart added successfully!"}
    else
      flash[:alert] = @insert_cart.errors.full_messages.to_sentence
      index()
      render action: :index
    end
  rescue => e
      flash[:alert] = "Cart adding error."
      index()
      render action: :index
  end
def create ( ) params = create_params @insert_cart = Cart . where ( :user_id => current_user . id , :product_id => params [ "product_id" ] ) . first if ! @insert_cart . nil? @insert_cart . quantity = Integer ( @insert_cart . quantity ) + Integer ( params [ "quantity" ] ) else @insert_cart = Cart . new ( params ) end if @insert_cart . save redirect_to "/browse" , flash : { notice : "Cart added successfully!" } else flash [ :alert ] = @insert_cart . errors . full_messages . to_sentence index ( ) render action : :index end rescue => e flash [ :alert ] = "Cart adding error." index ( ) render action : :index end
POST orders
Function to insert new item into cart.
POST orders Function to insert new item into cart .
# check if purchase already exists. # Guranteed to only have one in db.