Sha256: 42245869d9eed56c0d5365944d9a95f197ef67764597138e7b09efd149c00c2f
Contents?: true
Size: 887 Bytes
Versions: 24
Compression:
Stored size: 887 Bytes
Contents
module ManualSlug::Mongoid extend ActiveSupport::Concern include ::Mongoid::Slug def text_slug self._slugs.blank? ? '' : self._slugs.last end def text_slug=(slug) if slug.blank? self._slugs = [] else if self._slugs.blank? self._slugs = [slug] else self._slugs.delete(slug) self._slugs << slug end end end module ClassMethods def manual_slug(field, options = {}, callback = true) options.merge!(permanent: true, history: true) slug field, options # we will create slugs manually when needed skip_callback :create, :before, :build_slug before_validation do if self._slugs.blank? self.build_slug else self._slugs = self._slugs.map{ |s| s.strip }.select {|s| !s.blank? } end true end if callback end end end
Version data entries
24 entries across 24 versions & 2 rubygems