Sha256: 1e486cb8c31db5e514ee6de6676e7ba46d3dbe34107a537edb20fca1d8d7e1f8
Contents?: true
Size: 981 Bytes
Versions: 10
Compression:
Stored size: 981 Bytes
Contents
module ManualSlug::Mongoid extend ActiveSupport::Concern include ::Mongoid::Slug def text_slug ((self._slugs.nil? or self._slugs.empty?) ? '' : self._slugs.last) end def text_slug=(slug) self._slugs ||= [] if slug.blank? self._slugs = [] else self._slugs.delete(slug) self._slugs << slug end end module ClassMethods def manual_slug(_field, options = {}, callback = true) options.merge!(permanent: true, history: true) slug _field, options #overwrite for default value field :_slugs, type: Array, localize: options[:localize], default: [], overwrite: true # we will create slugs manually when needed skip_callback :create, :before, :build_slug before_validation do self._slugs = self._slugs.map{ |s| s.strip }.reject {|s| s.blank? } if self._slugs if self._slugs.blank? self.build_slug end true end if callback end end end
Version data entries
10 entries across 10 versions & 1 rubygems