Sha256: 8c6644c43959b2fbd930a6af0fdb6650723c81874b8dfec142c97a97322f532a

Contents?: true

Size: 815 Bytes

Versions: 3

Compression:

Stored size: 815 Bytes

Contents

class Blog::Blog < ActiveRecord::Base
  
  # -- Relationhips ---------------------------------------------------------
  belongs_to :site, :class_name => 'Cms::Site'
  
  has_many :posts,
    :dependent  => :destroy
  has_many :comments,
    :through    => :posts
    
  # -- Validations ----------------------------------------------------------
  validates :site_id, :label, :identifier,
    :presence   => true
  validates :identifier,
    :format     => { :with => /\A\w[a-z0-9_-]*\z/i }
  validates :path,
    :uniqueness => { :scope => :site_id },
    :format     => { :with => /\A\w[a-z0-9_-]*\z/i },
    :presence   => true,
    :if         => 'restricted_path?'
  
protected

  def restricted_path?
    (self.class.count > 1 && self.persisted?) ||
    (self.class.count >= 1 && self.new_record?)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comfy_blog-1.1.1 app/models/blog/blog.rb
comfy_blog-1.1.0 app/models/blog/blog.rb
comfy_blog-1.0.0 app/models/blog/blog.rb