Class: StoreModel::CombineErrorsStrategies::MergeErrorStrategy
- Inherits:
-
Object
- Object
- StoreModel::CombineErrorsStrategies::MergeErrorStrategy
- Defined in:
- lib/store_model/combine_errors_strategies/merge_error_strategy.rb
Overview
MergeErrorStrategy
copies errors from the StoreModel::Model to the parent record (for Rails < 6.1) or marks the attribute invalid (for Rails >= 6.1).
Instance Method Summary collapse
-
#call(attribute, base_errors, store_model_errors) ⇒ Object
Merges errors on
attribute
from the child model with parent errors.
Instance Method Details
#call(attribute, base_errors, store_model_errors) ⇒ Object
Merges errors on attribute
from the child model with parent errors.
attribute
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/store_model/combine_errors_strategies/merge_error_strategy.rb', line 14 def call(attribute, base_errors, store_model_errors) if Rails::VERSION::MAJOR < 6 || Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR.zero? base_errors.delete(attribute) store_model_errors.each { |field, error| base_errors.add(field, error) } else store_model_errors.errors.each do |error| base_errors.add(attribute, :invalid, message: error.) end end end |