Sha256: 449c5d8ced51b4e3798659551980d80352b4e32b73a11ddfb241dce73f7411f4
Contents?: true
Size: 836 Bytes
Versions: 11
Compression:
Stored size: 836 Bytes
Contents
module Cms class Site < ActiveRecord::Base #attr_accessible :name, :domain validates_uniqueness_of :domain before_validation :remove_www before_save :unset_default after_save :set_default scope :default, -> {where(:the_default => true)} def self.find_by_domain(domain) d = domain.clone strip_www!(d) if site = where(:domain => d).first 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 end
Version data entries
11 entries across 11 versions & 2 rubygems