Sha256: b2a79bee247b889b9bc90ce51195ec4757e78e6b72639c52fb980a1b7f2df622

Contents?: true

Size: 487 Bytes

Versions: 14

Compression:

Stored size: 487 Bytes

Contents

# frozen_string_literal: true

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

  before_save :set_slug

  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

14 entries across 14 versions & 1 rubygems

Version Path
pages_core-3.11.3 app/models/category.rb
pages_core-3.11.2 app/models/category.rb
pages_core-3.11.1 app/models/category.rb
pages_core-3.11.0 app/models/category.rb
pages_core-3.10.2 app/models/category.rb
pages_core-3.10.1 app/models/category.rb
pages_core-3.9.2 app/models/category.rb
pages_core-3.9.1 app/models/category.rb
pages_core-3.9.0 app/models/category.rb
pages_core-3.8.3 app/models/category.rb
pages_core-3.8.2 app/models/category.rb
pages_core-3.8.1 app/models/category.rb
pages_core-3.8.0 app/models/category.rb
pages_core-3.7.0 app/models/category.rb