daily pastebin goal
82%
SHARE
TWEET

Untitled

a guest Apr 22nd, 2018 50 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
Top