Skip to content

Instantly share code, notes, and snippets.

@lbramos
Last active August 29, 2015 14:13
Show Gist options
  • Save lbramos/740a6b14898d983c0558 to your computer and use it in GitHub Desktop.
Save lbramos/740a6b14898d983c0558 to your computer and use it in GitHub Desktop.
Validate fields depending on the another field value
#problem: validate field2 and field3 depending on value of field1
validates :field1, presence: true
validates :field2, presence: true, :if => Proc.new {|o| o.field1 == "Yes" }
validates :field3, presence: true, :if => Proc.new {|p| p.field1 == "No" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment