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?
- end
- end
Add Comment
Please, Sign In to add comment