Guest User

Untitled

a guest
Apr 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.32 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment