Sha256: 8c7028f8eb9578f8b00c4d7794855ca83951a529101fb56c5391fb42d5f7b07a
Contents?: true
Size: 773 Bytes
Versions: 35
Compression:
Stored size: 773 Bytes
Contents
class Site < ActiveRecord::Base validates_uniqueness_of :domain before_validation :remove_www before_save :unset_default after_save :set_default named_scope :default, :conditions => {:the_default => true} def self.find_by_domain(domain) d = domain.clone strip_www!(d) if site = first(:conditions => {:domain => d}) site else default.first end end def self.strip_www!(d) return unless d d.sub!(/\Awww./,'') end def remove_www self.class.strip_www!(domain) end def unset_default self.class.update_all(["the_default = ?", false]) if the_default end def set_default if self.class.default.count < 1 update_attribute(:the_default, true) end end end
Version data entries
35 entries across 35 versions & 11 rubygems