Reputation: 1433
Have 4 fields (alpha, beta, gamma, delta), at least 1 of them must have a value, ie not be nil/empty/blank. How can I create a validation to make sure of that?
Upvotes: 4
Views: 1133
Reputation: 222040
validate :something_must_be_set
def something_must_be_set
unless alpha || beta || gamma || delta
errors.add(:base, "Alpha, Beta, Gamma or Delta must be present.")
end
end
Upvotes: 7