<commit_before>class CartsController < ApplicationController
  def add
    dish = Dish.find(params[:id])
    if Cart.any?
      find_cart
    else
      @cart = Cart.create
    end
    session[:cart_id] = @cart.id
    @cart.add(dish, dish.price)
    flash[:notice] = "#{dish.name} added to cart"
    redirect_to restaurant_path(params[:restaurant_id])
  end

  def find_cart
    @cart = Cart.find(session[:cart_id]) if session[:cart_id]
  end
end<commit_msg>finding cart by session, getting that cart if it exists<commit_after>class CartsController < ApplicationController
  def add
    dish = Dish.find(params[:id])
    if session[:cart_id]
      find_cart
    else
      @cart = Cart.create
      session[:cart_id] = @cart.id
    end
    @cart.add(dish, dish.price)
    flash[:notice] = "#{dish.name} added to cart"
    redirect_to restaurant_path(params[:restaurant_id])
  end

  def find_cart
    @cart = Cart.find(session[:cart_id])
  end
end
{'fraction_non_alphanumeric': 0.11298838437170011, 'fraction_numerical': 0.0, 'mean_word_length': 3.3686635944700463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4104903', 'n_tokens_mistral': 321, 'n_tokens_neox': 317, 'n_words': 74}