Hi, I have a model which contains a boolean value. I would like to set
a validation which only allows this value to be set to true for one
record at a time in the table. Is it possible to do this with
validates_uniqueness? or is there another way?
Any help would be appreciated, thanks.
Is it possible to do this with
validates_uniqueness?
validates_uniqueness on a boolean would be great if you only ever want 2
records in your table…
Perhaps doing a quick count of records with the value set before saving
your current create/update would achieve what you want.
Dan S. wrote:
Hi, I have a model which contains a boolean value. I would like to set
a validation which only allows this value to be set to true for one
record at a time in the table. Is it possible to do this with
validates_uniqueness? or is there another way?
validates_uniqueness_of :is_root, :if => :is_root should work.
–
Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com