Module: ActiveRecord::Errors::Unique
- Included in:
- ActiveRecord::Errors
- Defined in:
- lib/vex/active_record/validation_error_ext.rb
Overview
better error reporting: this is useful mainly for development cycles, as it adds an error message only once
Instance Method Summary collapse
- #add(attribute, message = nil, options = {}) ⇒ Object
- #add_with_unique_messages(error_or_attr, message = nil, options = {}) ⇒ Object
- #delete(entry) ⇒ Object
Instance Method Details
#add(attribute, message = nil, options = {}) ⇒ Object
10 11 12 |
# File 'lib/vex/active_record/validation_error_ext.rb', line 10 def add(attribute, = nil, = {}) (attribute, , ) end |
#add_with_unique_messages(error_or_attr, message = nil, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/vex/active_record/validation_error_ext.rb', line 14 def (error_or_attr, = nil, = {}) if error_or_attr.is_a?(ActiveRecord::Error) error, attribute = error_or_attr, error_or_attr.attribute else attribute = error_or_attr error = ActiveRecord::Error.new(@base, attribute, , ) end [:message] = .delete(:default) if .has_key?(:default) @errors[attribute.to_s] ||= [] existing = @errors[attribute.to_s].detect do |err| err. == end existing || (@errors[attribute.to_s] << error) end |
#delete(entry) ⇒ Object
6 7 8 |
# File 'lib/vex/active_record/validation_error_ext.rb', line 6 def delete(entry) @errors.delete entry.to_s end |