Checking math equation with checking rails
1 answer
Override the method validate
in your model class. Remember that the model object created for the action new
is a different instance than the one created for the action create
, so you need to store the random seed or math expression somewhere in your form so you can recreate it during validation.
Then something line by line:
def validate
unless math_equation_answered?
errors.add("math_answer", "is incorrect")
end
end
The implementation is math_equation_answered?
up to you and math_answer
should be changed in any field in the model that you use to respond to the user.
+1
a source to share