Home Conditional validation not firing
Reply: 0

Conditional validation not firing

user990 Published in July 18, 2018, 10:24 pm

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 ?


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.295432 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO