class Tag < ApplicationRecord has_many :image_tags, dependent: :destroy has_many :images, through: :image_tags validates :name, presence: true, uniqueness: true before_save :downcase_name def self.ransackable_attributes(auth_object = nil) [ "created_at", "id", "id_value", "status", "name", "catalog", "updated_at", "user_id" ] end # Method to get the count of associated images def images_count images.count end private def downcase_name self.name = name.downcase if name.present? end end