Validate: Only one row set to boolean at any time

How can I validate that only one of the rows in my database is true and
rest are false at any give time?

I’ve already figured out to do this except if I try to update the row
that is true. Then it fails.

Here’s the code:

What needs to be done to make it work?

Uh, messed the subject line. It should say “true” instead of “boolean”
of course.

Another way I figured is:

validates_uniqueness_of :is_visitor

And then add a check: If is_visitor is true, validate, if it’s false,
then don’t. That would work perfectly but I don’t know how to access the
data being submitted for validation.

Ideas on how to do that?

Anyone have any ideas? I’m pretty stuck with this now.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs