Sha256: 26661ec4e224f63b78d56bfa57a9fc02e2994546313769cf3466fad1ebf2841b
Contents?: true
Size: 852 Bytes
Versions: 11
Compression:
Stored size: 852 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, :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 end
Version data entries
11 entries across 11 versions & 1 rubygems