Module: NestedAttributesUniqueness::Validator::ClassMethods
- Defined in:
- lib/nested_attributes_uniqueness/validator.rb
Instance Method Summary collapse
-
#validates_uniqueness_in_memory(collection_name, attribute, options = {}) ⇒ Object
This method adds an
after_validation
callback. -
#validates_uniqueness_in_memory_for_tree_polymorphism(polymorphic_association_name, type, collection_name, attribute, options = {}) ⇒ Object
This method adds an
after_validation
callback.
Instance Method Details
#validates_uniqueness_in_memory(collection_name, attribute, options = {}) ⇒ Object
This method adds an after_validation
callback.
Parameters
-
collection_name
- The association name that should be used for fetching collection. -
attribute
- The attribute name on the association that should be validated. -
options
- It accepts all options that ‘UniqunessValidator` accepts. Default to no options.
Example
# Without options
class User < ActiveRecord::Base
include NestedAttributesUniqueness
has_many :posts
validates_uniqueness_in_memory :posts, :name
end
# With options
class User < ActiveRecord::Base
include NestedAttributesUniqueness
has_many :posts
validates_uniqueness_in_memory :posts, :name, { case_sensitive: false }
end
189 190 191 192 193 |
# File 'lib/nested_attributes_uniqueness/validator.rb', line 189 def validates_uniqueness_in_memory(collection_name, attribute, = {}) after_validation do validate_unique_nested_attributes self, public_send(collection_name), attribute, end end |
#validates_uniqueness_in_memory_for_tree_polymorphism(polymorphic_association_name, type, collection_name, attribute, options = {}) ⇒ Object
This method adds an after_validation
callback.
Parameters
-
polymorphic_association_name
- Name of the tree polumorphic association with container and component as the name of polymorphic attributes -
type
- The component type in which to look for collection -
collection_name
- The association name that should be used for fetching collection. -
attribute
- The attribute name on the association that should be validated. -
options
- It accepts all options that ‘UniqunessValidator` accepts. Defaults to no options. Supports scope and case_sensitive options
208 209 210 211 212 |
# File 'lib/nested_attributes_uniqueness/validator.rb', line 208 def validates_uniqueness_in_memory_for_tree_polymorphism(polymorphic_association_name, type, collection_name, attribute, = {}) after_validation do validate_unique_nested_attributes_for_tree_polymorphism self, polymorphic_association_name, type, collection_name, attribute, end end |