Module: ValidationGroup::ActiveRecord::Errors

Defined in:
lib/validation_group.rb

Overview

included in ActiveRecord::Errors

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



123
124
125
126
127
# File 'lib/validation_group.rb', line 123

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

gaveeno: modified this method to fix error associated with deprecated method per this comment: alexkira.blogspot.com/2007/09/rails-validation-using-validation.html?showComment=1235667300000#c1858075936669114503 def add_with_validation_group(attribute, msg = @@default_error_messages, *args, &block)



109
110
111
112
113
114
115
# File 'lib/validation_group.rb', line 109

def add_with_validation_group(attribute, msg = I18n.translate('activerecord.errors.messages')[:invalid], *args, &block)
  # jeffp: setting @current_validation_fields and use of should_validate? optimizes code
  # gaveeno: modified this method to add error if the error is on the base object and not on an attribute.
  # this is necessary to work with the advanced_exceptions plugin.
  add_error = @base.respond_to?(:should_validate?) ? (@base.should_validate?(attribute.to_sym) || attribute == :base) : true
  add_without_validation_group(attribute, msg, *args, &block) if add_error
end

#remove_on(attributes) ⇒ Object



117
118
119
120
121
# File 'lib/validation_group.rb', line 117

def remove_on(attributes)
  return unless attributes
  attributes = [attributes] unless attributes.is_a?(Array)
  @errors.reject!{|k,v| !attributes.include?(k.to_sym)}
end