Validation to ensure uniqueness of but ignoring empty values?

Yes, there are two possible options that you can pass to validations for optional fields: :allow_blank or :allow_nil, which will skip the validations on blank and nil fields, respectively. If you change your validation to the following, you should get the behaviour you want:

validates_uniqueness_of :acronym, :allow_blank => true, :scope => [:group_id], :case_sensitive => false

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)