Home Conditional validation not firing
Reply: 0

Conditional validation not firing

Jerome
1#
Jerome Published in 2018-01-12 15:04:44Z

Using a gem for validating date overlap, the attempt is to verify against existing records whether the new records overlaps for non-cancelled records. The class has attribute cancelled as boolean, default: false.

It appears the following syntax is erroneous as the application rollsback when hitting and existing cancelled object.

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

what is the proper way to do this under rails 4.2 ?

Update

following the gem's conventions

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

does not fire either.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303728 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO