John
John

Reputation: 1433

Rails 3 validation, multiple fields

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

Answers (1)

Dogbert
Dogbert

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

Related Questions