[英]How does Conditional Validation work in rails
Looking through the rails code, I can't see where conditional validation gets executed... when you pass a string or an symbol to :if
it supposedly does an eval
for strings and a send
for symbols... where does that happen? 在rails代码中查看,我看不到条件验证在哪里执行...当您将字符串或符号传递给
:if
它应该对字符串进行eval
而对符号进行send
...在哪里发生?
Been trying to follow it through the code but I can't find where the if
options are split into send
or eval
and how that all works. 一直试图通过代码来遵循它,但是我找不到
if
选项在哪里分成send
或eval
以及它们如何工作。 Just trying to learn and follow the through how rails does it. 只是尝试学习并遵循Rails的操作方式。
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validator.rb https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations.rb https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validator.rb https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations.rb
Thanks! 谢谢!
This method is responsible for all the symbols, strings and lambdas being executed. 此方法负责执行所有符号,字符串和lambda。 Seems that Rails is using
activesupport callbacks
to implement validations. 似乎Rails正在使用
activesupport callbacks
来实现验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.