条件验证未触发

时间:2018-01-12 15:04:44

标签: ruby-on-rails validation

使用gem for validating date overlap,尝试针对现有记录验证新记录是否与未取消记录重叠。该类的属性cancelled为boolean,默认值为:false。

当命中和现有被取消的对象时应用程序回滚,似乎以下语法是错误的。

validates :start_time, :end_time, :overlap => {:scope => "instructor_id", :exclude_edges => ["start_time", "end_time"]}, if: -> {cancelled == false || require_validation}

在rails 4.2下执行此操作的正确方法是什么?

更新

遵循宝石的惯例

validates :start_time, :end_time, :overlap => {:query_options => {:cancelled => nil}, :scope => "instructor_id", :exclude_edges => ["start_time", "end_time"]}
scope :cancelled, -> { where(:cancelled => false) }

也不会开火。

0 个答案:

没有答案