T
T
Tinord2018-02-07 10:04:23
JavaScript
Tinord, 2018-02-07 10:04:23

Which function in ruby/javascript collapses a table?

Good day.
There is a site written in Ruby, in which there are a lot of crutches (4 freelancers worked on the site). The problem is that when the amount of goods in the basket increases, the table automatically collapses and the delivery is reset to zero.
Question: where does the incorrect processing occur, on the server or user side?
5a7aa278991a4753395250.png
5a7aa32a22711925364210.png
javascript

var postQuantity = Restangular.all('api/quantity.json');

  $scope.plusQuantity = function(id, type) {
    $scope.quantityPromise = postQuantity.post({id: id, type: type, method: 'plus'}).then(
      function(success) {
        // refresher_cart_stat();
        $scope.getCart();

      },
      function(data) { if (debug) { console.log("ERROR_ID75343354", data); if (is_safari) { alert('ERROR_ID93487534'); location.reload(); } } }
    );
  };

  $scope.minusQuantity = function(id, type) {
    $scope.quantityPromise = postQuantity.post({id: id, type: type, method: 'minus'}).then(
      function(success) {
        // refresher_cart_stat();
        $scope.getCart();
      },
      function(data) { if (debug) { console.log("ERROR_ID85844445", data); if (is_safari) { alert('ERROR_ID84930584'); location.reload(); } } }
    );
  };

ruby
get :add, :map => '/add-to-cart/:id' do
    type = params[:type].present? ? params[:type] : "standard"
    curr_item = { "id" => params[:id], "quantity" => params[:quantity], "type" => type }
    if session[:cart].nil?
      cart = Array.new()
    else
      cart = session[:cart]
    end
    incart = false
    cart.each_with_index do |item, index|
      if item["id"] == curr_item["id"] && (item["type"] == curr_item["type"] || (item["type"].blank? && curr_item["type"] == "standart" ))
        cart[index]["quantity"] = (cart[index]["quantity"].to_i + curr_item["quantity"].to_i).to_s
        incart = true
      end
    end
    if incart
      session[:cart] = cart
    else
      session[:cart] = cart.push(curr_item)
    end
    #redirect(back, :notice => 'Товар добавлен в корзину.')
    
    erb 'SUCCESS!'

  end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SilentFl, 2018-02-15
@Tinord

it seems to me that this caching spoils everything for you - '/add-to-cart/:id' should hang on the post-request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question