19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/manual_slug/mongoid.rb', line 19
def manual_slug(_field, options = {}, callback = true)
options.merge!({
permanent: true,
history: true,
scope: (Hancock.config.mongoid_single_collection ? :_type : nil)
})
slug _field, options
field :_slugs, type: Array, localize: options[:localize], default: [], overwrite: true
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
|