Module: ValidationGroup::ActiveRecord::Errors
- Defined in:
- lib/validation_group.rb
Overview
included in ActiveRecord::Errors
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #add_with_validation_group(attribute, msg = , *args, &block) ⇒ Object
- #remove_on(attributes) ⇒ Object
Class Method Details
.included(base) ⇒ Object
:nodoc:
120 121 122 123 124 |
# File 'lib/validation_group.rb', line 120 def self.included(base) #:nodoc: base.class_eval do alias_method_chain :add, :validation_group end end |
Instance Method Details
#add_with_validation_group(attribute, msg = , *args, &block) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/validation_group.rb', line 106 def add_with_validation_group(attribute, msg = @@default_error_messages[:invalid], *args, &block) # jeffp: setting @current_validation_fields and use of should_validate? optimizes code add_error = @base.respond_to?(:should_validate?) ? @base.should_validate?(attribute.to_sym) : true add_without_validation_group(attribute, msg, *args, &block) if add_error end |
#remove_on(attributes) ⇒ Object
114 115 116 117 118 |
# File 'lib/validation_group.rb', line 114 def remove_on(attributes) return unless attributes attributes = [attributes] unless attributes.is_a?(Array) @errors.reject!{|k,v| !attributes.include?(k.to_sym)} end |