Search code examples
ruby-on-railsruby-on-rails-3slug

How to validate uniqueness then suggest a unique alternative on fail


I want to create slugs based on a title field, so those slugs will have to be unique.

Is there a callback method for when validates_uniqueness_of fails so that i can append a character to the end of the slug to make it unique?


Solution

  • Sounds like this would be better as a before_create callback than a validation. It's not actually invalid if the name's a dupe; you just need to uniquify it.