Sha256: 44792fee7ba8edbc49666317ed2c76ba36b55e3006745f4cb22ac0c8de716b8c

Contents?: true

Size: 643 Bytes

Versions: 8

Compression:

Stored size: 643 Bytes

Contents

class Category < ActiveRecord::Base
  unloadable
  
  has_many :articles
  
  validates_presence_of :title
  validates_uniqueness_of :title
  
  named_scope :with, lambda { |many| {:joins => many.to_sym, :group => 'categories.id'} }
  
  before_save :set_url
  before_destroy :no_content?

  def has_content?
    has_content = false
    self.class.reflect_on_all_associations.each do |assoc|
      if send(assoc.name).any?
        has_content = true
        break
      end
    end
    return has_content
  end
  
  def no_content?
    !has_content?
  end

private

  def set_url
    write_attribute :permalink, title.parameterize
  end  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
beef-articles-0.3.13 app/models/category.rb
beef-articles-0.3.14 app/models/category.rb
beef-articles-0.3.15 app/models/category.rb
beef-articles-0.3.16 app/models/category.rb
beef-articles-0.3.18 app/models/category.rb
beef-articles-0.3.21 app/models/category.rb
beef-articles-0.3.25 app/models/category.rb
beef-articles-0.3.27 app/models/category.rb