<commit_before>class Animal < ApplicationRecord
	belongs_to :area
	has_many :baby_animals

	validates :name, presence: true
	validates :age, presence: true
	validates :sex, presence: true
	validates :color, presence: true
	validates :weight, presence: true

	scope :goat, -> { where(animal_type: "goat") }
	scope :large, -> { where('weight > ?', 100) }

	before_save :erase_empty_baby_animals

	def baby_animals_attributes=(baby_animals_attributes)
		baby_animals_attributes.values.each do |baby_animal_attributes|
			if baby_animal_attributes[:_destroy].present?
				baby_animal_attributes.destroy
			else
				self.baby_animals.build(baby_animal_attributes)	
			end
		end
	end

	def erase_empty_baby_animals
		self.baby_animals = self.baby_animals.select { |b| b.name != ''}
	end

end<commit_msg>implementing destroy check box on edit animal form<commit_after>class Animal < ApplicationRecord
	belongs_to :area
	has_many :baby_animals

	validates :name, presence: true
	validates :age, presence: true
	validates :sex, presence: true
	validates :color, presence: true
	validates :weight, presence: true

	scope :goat, -> { where(animal_type: "goat") }
	scope :large, -> { where('weight > ?', 100) }

	before_save :erase_empty_baby_animals

	def baby_animals_attributes=(baby_animals_attributes)
		baby_animals_attributes.each do |i, baby_animal_attributes|
			if baby_animal_attributes[:_destroy] == "1"
				self.baby_animals_attributes.clear
			else
				self.baby_animals.build(baby_animal_attributes)	
			end
		end
	end

	def erase_empty_baby_animals
		self.baby_animals = self.baby_animals.select { |b| b.name != ''}
	end

end
{'fraction_non_alphanumeric': 0.09515039901780234, 'fraction_numerical': 0.004297114794352364, 'mean_word_length': 5.221374045801527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7419905', 'n_tokens_mistral': 624, 'n_tokens_neox': 550, 'n_words': 124}