DaniG2k
DaniG2k

Reputation: 4893

Adding one error message to two checkboxes in Rails

I have two checkboxes that I'm adding a simple custom validator on. I want to check that either one or the other (or both) are checked, but that they aren't both empty.

To do this, I've written put a simple unless checkbox1 || checkbox2 line in my custom validator method. However, when outputting the error message, I realized that the error.add takes the form field as first parameter. I don't want the error message to be specifically for one of the other checkbox; I just want it to say, one or both need to be selected. How can I do this?

Upvotes: 0

Views: 62

Answers (1)

DaniG2k
DaniG2k

Reputation: 4893

Just found the answer:

errors.add(:base, 'Generic error message')

Upvotes: 0

Related Questions