Sha256: 3c614976f1dcbba76432b1a27705022d38845b738663d167e757fa5a54897b0e
Contents?: true
Size: 501 Bytes
Versions: 6
Compression:
Stored size: 501 Bytes
Contents
class FeaturedWork < ActiveRecord::Base FEATURE_LIMIT = 5 validate :count_within_limit, on: :create validates :order, inclusion: { in: proc { 0..FEATURE_LIMIT } } default_scope { order(:order) } def count_within_limit return if FeaturedWork.can_create_another? errors.add(:base, "Limited to #{FEATURE_LIMIT} featured works.") end attr_accessor :generic_file_solr_document class << self def can_create_another? FeaturedWork.count < FEATURE_LIMIT end end end
Version data entries
6 entries across 6 versions & 1 rubygems