79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/sluggable_finder/orm.rb', line 79
def create_sluggable_slug
suffix = ''
begin
proposed_slug = if self.send(destination_column.to_sym).blank? SluggableFinder.encode get_value_or_generate_random(source_column.to_sym) else
SluggableFinder.encode get_value_or_generate_random(destination_column.to_sym) end
rescue Exception => e
raise e
end
cond = if new_record?
''
else
"id != #{id} AND "
end
slugable_class.transaction do
existing = slugable_class.find(:first, :conditions => ["#{cond}#{destination_column} LIKE ? and #{scope_condition}", proposed_slug + suffix])
while existing != nil or sluggable_finder_options[:reserved_slugs].include?(proposed_slug + suffix)
if suffix.empty?
suffix = "-2"
else
suffix.succ!
end
existing = slugable_class.find(:first, :conditions => ["#{cond}#{destination_column} = ? and #{scope_condition}", proposed_slug + suffix])
end
end proposed_slug + suffix
end
|