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 22
def manual_slug(field, options = {}, callback = true)
unless options.key?(:permanent)
options[:permanent] = true
end
unless options.key?(:history)
options[:history] = true
end
slug field, options
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
|