53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/railhead_permalink.rb', line 53
def create_permalink
if self.permalink.nil? or (self.changed.include?(permalink_options[:field].to_s) and not permalink_options[:keep_existing])
key = self[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
|