0

I'm using FriendlyId gem on Ruby on Rails 5.

Is there any way to stop FriendlyId to create a different slug if the current one has already been taken? I'd like the user to have full control over the slug.

a.barbieri
  • 2,398
  • 3
  • 30
  • 58

1 Answers1

0

Add this method to your Model.

def should_generate_new_friendly_id?
  new_record?
end

or modify the content of the method to match your needs.

Sebastian Delgado
  • 706
  • 3
  • 7
  • 26
  • Yes, I know this method, but this runs before creating the `slug`, so I cannot check against it. If you look at the source code you can see what I mean. I'd need to avoid creating a new `slug` if the first attempt fails. See [this line](https://github.com/norman/friendly_id/blob/d29ec3de0317d73a09b728b945470c19e6273caf/lib/friendly_id/slugged.rb#L308-L312). Do you know how to achieve it? – a.barbieri Apr 06 '17 at 13:48