59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/railhead_permalink.rb', line 59
def create_permalink
if self.permalink.nil? or (self.changed.include?(permalink_options[:field].to_s) and not permalink_options[:keep_existing])
key = self.send(permalink_options[:field]).to_url
unless self.permalink == key
permalink, counter = key, '-1'
while permalink_options[:reserved_names].include?(permalink) or permalink.blank? or
(object = self.class.where(permalink: permalink).first and object != self)
counter.succ!
permalink = key + counter
end
self.permalink = permalink
end
end
true
end
|