Class: Releaf::Content::Node::RootValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Releaf::Content::Node::RootValidator
- Defined in:
- app/validators/releaf/content/node/root_validator.rb
Overview
Validator to test if node is valid root node
Validator needs :allow option.
:allow option specifies which nodes are valid root nodes.
In example above only Text and Book nodes can be created as root nodes
Instance Method Summary collapse
Instance Method Details
#validate(node) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/validators/releaf/content/node/root_validator.rb', line 19 def validate node @node = node if allowed_root_node? node.errors.add(:content_type, "can't be subnode") if @node.parent.present? else node.errors.add(:content_type, "can't be root node") if @node.parent.nil? end remove_instance_variable(:@node) end |