0

The new version of friendly_id uses a slug_candidates method to create the slugged values appending a uuid if a duplicate is found, how do use this to get the old functionality? i.e matching records will be appended with 1,2,3 etc.

  def slug_candidates
    [
      :title,
      [:title, 'code that creates a sequential number']
    ]
  end
raphael_turtle
  • 7,154
  • 10
  • 55
  • 89

1 Answers1

0

What about adding a method like

def duplicates_count
  Model.where(title: self.title).count + 1 # Model is whatever the model is
end

and slug_candidates method would become

def slug_candidates
  [
    :title,
    [:title, :duplicates_count]
  ]
end

Would something like this work for you? Hopefully this helps!

strivedi183
  • 4,749
  • 2
  • 31
  • 38