Rails validate uniqueness only if conditional
You can make a validation conditional by passing either a simple string of Ruby to be executed, a Proc, or a method name as a symbol as a value to either :if or :unless in the options for your validation. Here are some examples: Prior to Rails version 5.2 you could pass a string: # … Read more