daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Apr 22nd, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MyValidator < ActiveModel::Validator
  2.   def validate(record)
  3.     parent_query = record.page.sections.where("parent_id is NULL")
  4.     parent_query = parent_query.where("id != ?", record.id) unless record.new_record?
  5.  
  6.     record.errors[:base] << "Cant have multiple roots" if parent_query.parent_exists?
  7.   end
  8. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top