<commit_before>class ProductsController < ApplicationController
  include CurrentCart
  before_action :set_cart
  load_and_authorize_resource
  skip_before_action :authenticate_user!, only: [:index, :show]

  before_action :set_product, only: [:show, :edit, :update, :destroy]

  # GET /products
  # GET /products.json
  def index
    if params[:category]
      @products = Product.where(category: params[:category]).all
      @category = Category.find(params[:category])
    else
      redirect_to store_path
    end
  end

  # GET /products/1
  # GET /products/1.json
  def show
    @product = Product.find(params[:id])
  end

  # GET /products/new
  def new<commit_msg>Add avg_rating to product show method<commit_after>class ProductsController < ApplicationController
  include CurrentCart
  before_action :set_cart
  load_and_authorize_resource
  skip_before_action :authenticate_user!, only: [:index, :show]

  before_action :set_product, only: [:show, :edit, :update, :destroy]

  # GET /products
  # GET /products.json
  def index
    if params[:category]
      @products = Product.where(category: params[:category]).all
      @category = Category.find(params[:category])
    else
      redirect_to store_path
    end
  end

  # GET /products/1
  # GET /products/1.json
  def show
    @product = Product.find(params[:id])

    @reviews = @product.reviews.to_a
    @avg_rating = if @reviews.blank?
      0
    else
      @product.reviews.average(:rating).round(2)
    end
  end

  # GET /products/new
  def new
{'fraction_non_alphanumeric': 0.10481212920237311, 'fraction_numerical': 0.003955174686882004, 'mean_word_length': 3.5449101796407185, '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': '3208949', 'n_tokens_mistral': 489, 'n_tokens_neox': 474, 'n_words': 115}