<commit_before>class Product < ActiveRecord::Base

  has_crud orderable: true, settings: true
  has_many :product_images
  accepts_nested_attributes_for :product_images, allow_destroy: true

  belongs_to :category

  # FIXME: Refactored from has
  has_many :images

  has_and_belongs_to_many :products,
    join_table: "related_products",
    foreign_key: "product_a_id",
    association_foreign_key: "product_b_id"

  acts_as_taggable_on :genre
  serialize :countries

  dragonfly_accessor :banner
  dragonfly_accessor  :manual

  Size = ["XL", "L", "M", "S", "XS"]
  Countries = ["Australia", "France", "Germany", "Greece"]
  Colours = ["Red", "Blue", "Green"]

  validates :name, presence: true

  # validates :name, :short_description, :description,
  #           :publish_date, :launch_date, :genre_list,
  #           :banner, :manual, :size, :colour,
  #           presence: true

  # validate :at_least_one_country

  def at_least_one_country
    errors.add :countries, "Please select at least one country" if countries.blank? || countries.reject(&:blank?).compact.empty?
  end

  crud.config do
    fields launch_date: { type: :date },
           short_description: { type: :text },
           genre_list: { type: :nice_tags },
           active: { type: :boolean },
           size: { type: :select, data: Size },
           countries: { type: :check_boxes, data: Countries },
           colour: { type: :radio, data: Colours },
           banner: { type: :image },
           manual: { type: :file },
           products: { type: :multiselect_association },
           product_images: { type: :inline },
           description: { type: :rich_text }

    config :admin do
      index fields: [:name]
       form  fields: [:name, :description, :products, :product_images]
    end<commit_msg>added colour field to products form using new colour picker<commit_after>class Product < ActiveRecord::Base

  has_crud orderable: true, settings: true
  has_many :product_images
  accepts_nested_attributes_for :product_images, allow_destroy: true

  belongs_to :category

  # FIXME: Refactored from has
  has_many :images

  has_and_belongs_to_many :products,
    join_table: "related_products",
    foreign_key: "product_a_id",
    association_foreign_key: "product_b_id"

  acts_as_taggable_on :genre
  serialize :countries

  dragonfly_accessor :banner
  dragonfly_accessor  :manual

  Size = ["XL", "L", "M", "S", "XS"]
  Countries = ["Australia", "France", "Germany", "Greece"]

  validates :name, presence: true

  # validates :name, :short_description, :description,
  #           :publish_date, :launch_date, :genre_list,
  #           :banner, :manual, :size, :colour,
  #           presence: true

  # validate :at_least_one_country

  def at_least_one_country
    errors.add :countries, "Please select at least one country" if countries.blank? || countries.reject(&:blank?).compact.empty?
  end

  crud.config do
    fields launch_date: { type: :date },
           short_description: { type: :text },
           genre_list: { type: :nice_tags },
           active: { type: :boolean },
           size: { type: :select, data: Size },
           countries: { type: :check_boxes, data: Countries },
           colour: { type: :colour },
           banner: { type: :image },
           manual: { type: :file },
           products: { type: :multiselect_association },
           product_images: { type: :inline },
           description: { type: :rich_text }

    config :admin do
      index fields: [:name]
       form  fields: [:name, :description, :products, :product_images, :colour]
    end
{'fraction_non_alphanumeric': 0.11736958934517203, 'fraction_numerical': 0.0, 'mean_word_length': 3.115296803652968, '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': '797887', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1126, 'n_words': 291}