I have the following model field validation:
validates_uniqueness_of :acronym, :scope => [:group_id], :case_sensitive => false
The problem is that this field is optional, and a empty/nil value is returning as being an acronym already taken. I only want to validate that an acronym is unique if a value was provided.. Is there a way to update this validation to only take place if there is an actual value.. not nil/empty?
Thanks
Yes, there are two possible options that you can pass to validations for optional fields:
:allow_blankor:allow_nil, which will skip the validations onblankandnilfields, respectively. If you change your validation to the following, you should get the behaviour you want: