Skip to content

Instantly share code, notes, and snippets.

@blelump
Created March 11, 2016 14:10
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 blelump/6ef879b3a7bae47287a5 to your computer and use it in GitHub Desktop.
Save blelump/6ef879b3a7bae47287a5 to your computer and use it in GitHub Desktop.
validation :email do
key(:email).required
end
validation :after_email, if: lambda { |results| results[:email]==true } do # extends the above.
key(:username).required
end
# block gets evaled in form instance context.
validation :password, if: lambda { |results| email == "john@trb.org" } do
key(:password).required
end
rule(:user_inactive, user_active?: [:email])
rule(:password_invalid, password_valid?: [:email, :password])
rule(:password_invalid) do
value(:email).user_active? & value(:email).password_valid?(value(:password))
end # It doesn't work as expected since if user is inactive, then it returns false and also puts :password_invalid into errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment