Using unless in rails uniqueness validation
Posted
by dunxd
on Stack Overflow
See other posts from Stack Overflow
or by dunxd
Published on 2010-05-21T14:05:48Z
Indexed on
2010/05/23
1:31 UTC
Read the original article
Hit count: 247
I am just starting out in Rails, and trying to develop a simple application. I need to validate three values submitted to the application - each must meet the same validation criteria.
The validation is pretty simple: Value is valid if unqiue, null or equal to "p" or "d".
The following gets me halfway there:
validates_uniqueness_of :value1, :value2, :value3, :allow_nil => true
I think I can use :unless to check whether the value is either "p" or "d", however I can't figure out how.
I guess I am trying to combine validates_uniqueness_of with validates_inclusion_of.
Any suggestions?
© Stack Overflow or respective owner