Sha256: cb801d9c96c9ea23784b0538adf41b674f0baadc4a0a378524a1466703b9b248
Contents?: true
Size: 1000 Bytes
Versions: 62
Compression:
Stored size: 1000 Bytes
Contents
module Workarea module Navigable extend ActiveSupport::Concern included do field :slug, type: String index({ slug: 1 }, { unique: true }) validates :slug, presence: true, uniqueness: true has_one :taxon, inverse_of: :navigable, class_name: 'Workarea::Navigation::Taxon', dependent: :destroy before_validation :generate_slug, if: proc { |l| l.slug.blank? } after_validation :reset_slug!, if: proc { |l| l.errors.present? } after_save :update_taxon_slug end def to_param slug end def slug=(val) if val.nil? super(val) else super(val.to_s.parameterize) end end private def generate_slug return nil unless name.present? self.slug = FindUniqueSlug.new(self, name.delete("'").parameterize).slug end def update_taxon_slug return if taxon.blank? || changes['slug'].blank? taxon.set(navigable_slug: slug) end end end
Version data entries
62 entries across 62 versions & 1 rubygems
Version | Path |
---|---|
workarea-core-3.4.13 | app/models/workarea/navigable.rb |
workarea-core-3.4.12 | app/models/workarea/navigable.rb |