0

In rails, I could restrict certain attribute to be unique within scope but pass on nil or blank. How could I ensure uniqueness but pass on certain value?

I encrypted an attribute, so it's not nil anymore. But I do allow nil for this attribute in the model.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
sean an
  • 127
  • 1
  • 2
  • 12
  • What do you mean by "Pass on nil or blank"? – ruby_newbie Dec 29 '15 at 19:58
  • 2
    Have you seen this [question](https://stackoverflow.com/questions/20914899/rails-validate-uniqueness-only-if-conditional)? You should be able to add any conditional logic you need to using `if: ->{...}`. – pdoherty926 Dec 29 '15 at 20:01

0 Answers0