Skip to content

Instantly share code, notes, and snippets.

@benoror
Last active May 17, 2019 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benoror/acbcd7ae816eb2e57463240c6bda988c to your computer and use it in GitHub Desktop.
Save benoror/acbcd7ae816eb2e57463240c6bda988c to your computer and use it in GitHub Desktop.
Rails Model XOR Validation for "Custom" fields

XOR Validation

validate :disease_or_custom_disease

#...

private
def disease_or_custom_disease
  custom_disease.blank? ^ disease_id.blank?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment