lib/permalink/orm/base.rb in permalink-1.2.0 vs lib/permalink/orm/base.rb in permalink-1.2.1
- old
+ new
@@ -35,23 +35,23 @@
end
end.reject(&:blank?).join("-")
end
private
- def next_available_permalink(_permalink)
- the_permalink = _permalink
+ def next_available_permalink(permalink)
+ unique_permalink = permalink
if self.class.permalink_options[:unique]
suffix = 2
- while self.class.where(to_permalink_name => the_permalink).first
- the_permalink = "#{_permalink}-#{suffix}"
+ while self.class.where(to_permalink_name => unique_permalink).first
+ unique_permalink = "#{permalink}-#{suffix}"
suffix += 1
end
end
- the_permalink
+ unique_permalink
end
def from_permalink_name
self.class.permalink_options[:from_column_name]
end
@@ -67,10 +67,10 @@
def to_permalink_value
read_attribute(to_permalink_name)
end
def update_permalink?
- self.class.permalink_options[:force] || to_permalink_value.blank?
+ changes[from_permalink_name] && (self.class.permalink_options[:force] || to_permalink_value.blank?)
end
def create_permalink
if update_permalink?
write_attribute(to_permalink_name, next_available_permalink(from_permalink_value.to_s.to_permalink))