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_validationcallback. -
#validates_uniqueness_in_memory_for_tree_polymorphism(polymorphic_association_name, type, collection_name, attribute, options = {}) ⇒ Object
This method adds an
after_validationcallback.
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 thatUniqunessValidatoraccepts. 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
186 187 188 189 190 |
# File 'lib/nested_attributes_uniqueness/validator.rb', line 186 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 thatUniqunessValidatoraccepts. Defaults to no options. Supports scope and case_sensitive options
205 206 207 208 209 |
# File 'lib/nested_attributes_uniqueness/validator.rb', line 205 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 |