Skip to content

Commit

Permalink
Last slug sequence bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Gil Vandendriessche committed Oct 10, 2016
1 parent 70f99e5 commit d8594bf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/friendly_id/sequentially_slugged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.setup(model_class)
end

def resolve_friendly_id_conflict(candidate_slugs)
candidate = candidate_slugs.to_a.last
candidate = candidate_slugs.first
return if candidate.nil?
SequentialSlugCalculator.new(scope_for_slug_generator,
candidate,
Expand Down Expand Up @@ -36,9 +36,11 @@ def next_sequence_number
end

def last_sequence_number
if match = /#{slug}#{sequence_separator}(\d+)\z/.match(slug_conflicts.last)
match[1].to_i
end
# Reject slug_conflicts that doesn't come from the first_candidate
# Map all sequence numbers and take the maximum
slug_conflicts.reject{ |slug_conflict| !regexp.match(slug_conflict) }.map do |slug_conflict|
regexp.match(slug_conflict)[1].to_i
end.max
end

def slug_conflicts
Expand Down

0 comments on commit d8594bf

Please sign in to comment.