README.md in nested_validator-1.0.4 vs README.md in nested_validator-1.0.5
- old
+ new
@@ -92,10 +92,27 @@
puts parent.errors.messages
# => {:"child attribute1"=>["can't be blank"]}
```
+### OK, is there a way to require one of several attributes?
+
+Yes. You can use the ```any``` option which requires that at least
+one of the specified child attributes is valid:
+
+``` ruby
+class ParentExcept < ParentBase
+ validates :child, nested: { any: [:attribute1, :attribute2] }
+end
+
+parent = ParentExcept.new
+parent.valid?
+puts parent.errors.messages
+
+ # => {:"child attribute1"=>["can't be blank"], :"child attribute2"=>["can't be blank"]}
+```
+
### Alright, what if I want a custom message?
You can specify a ```prefix``` instead of the child's attribute name:
``` ruby
@@ -181,9 +198,10 @@
it { should validate_nested(:child).with_prefix(:thing1) }
it { should validate_nested(:child).only(:attribute1) }
it { should validate_nested(:child).only(:attribute1, :attribute2) }
it { should validate_nested(:child).except(:attribute1) }
it { should validate_nested(:child).except(:attribute1, :attribute2) }
+ it { should validate_nested(:child).any(:attribute1, :attribute2) }
end
```
## Contributing
1. Fork it ( https://github.com/dwhelan/nested_validator/fork )