Sha256: fae2cdcf624572c77523ccc2395d12b2bce0d8e60b2ab5b0d7cca0cac03461f7
Contents?: true
Size: 484 Bytes
Versions: 72
Compression:
Stored size: 484 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 :presenter class << self def can_create_another? FeaturedWork.count < FEATURE_LIMIT end end end
Version data entries
72 entries across 72 versions & 3 rubygems