a guest Apr 22nd, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- class MyValidator < ActiveModel::Validator
- def validate(record)
- parent_query = record.page.sections.where("parent_id is NULL")
- parent_query = parent_query.where("id != ?", record.id) unless record.new_record?
- record.errors[:base] << "Cant have multiple roots" if parent_query.parent_exists?
RAW Paste Data