Sha256: 87bdfe293ba6f3e363a18436c465aa5154b6b33e74026ef023c3a22324dd1947

Contents?: true

Size: 544 Bytes

Versions: 1

Compression:

Stored size: 544 Bytes

Contents

# encoding: utf-8

class Category < ActiveRecord::Base
  has_many :page_categories, dependent: :destroy
  has_many :pages, through: :page_categories
  validates :name, presence: true
  acts_as_list

  before_save :set_slug
  after_save ThinkingSphinx::RealTime.callback_for(:pages, [:page])

  scope :by_name, -> { order("name ASC") }

  private

  def set_slug
    self.slug = name.downcase
                    .gsub(/[^\w\s]/, "")
                    .split(/[^\w\d\-]+/)
                    .compact
                    .join("-")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pages_core-3.5.1 app/models/category.rb