Rails:验证中的多个 if 条件
使用:Rails 3.0.3
我有这样的验证:
validates_numericality_of :person_weight_kg, :greater_than => 0, :message => "value_must_be_number_over_zero", :if => :bmi_calculation?, :if => :is_metric?
我想验证多个 if 条件(例如示例中)。但是,Rails 似乎将这些语句视为 OR。一个返回 false,一个返回 true,这使得验证通过。
那么,如何检查此验证是否满足两个 if 语句(bmi_calculation 和 is_metric)?
Using: Rails 3.0.3
I have validations such as this one:
validates_numericality_of :person_weight_kg, :greater_than => 0, :message => "value_must_be_number_over_zero", :if => :bmi_calculation?, :if => :is_metric?
That I would like to validate for multiple if-conditions (such as in the example). But it seems, however, that Rails treats these statements as OR. One returns false and one returns true which makes the validation go through.
So, how do I check that this validation fulfills BOTH if-statements (bmi_calculation AND is_metric)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 lambda 作为
if
条件:Use a lambda as the
if
condition: