class ProductsController < ApplicationController
def index
@products = Product
.includes(:category)
.order(created_at: :desc)
.page(params[:page])
class Product < ApplicationRecord
has_many :reviews, dependent: :destroy
scope :published, -> { where(published: true) }
def average_rating