diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb index d8b223940b..75399ea7f9 100644 --- a/config/initializers/10-patches.rb +++ b/config/initializers/10-patches.rb @@ -58,11 +58,12 @@ module ActiveModel # dependent on specific errors (which we use in the APIv3). # We therefore add a second information store containing pairs of [symbol, translated_message]. def add_with_storing_error_symbols(attribute, message = :invalid, options = {}) + error_symbol = options.fetch(:error_symbol) { message } add_without_storing_error_symbols(attribute, message, options) if store_new_symbols? - if message.is_a?(Symbol) - symbol = message + if error_symbol.is_a?(Symbol) + symbol = error_symbol partial_message = normalize_message(attribute, message, options) full_message = full_message(attribute, partial_message) else @@ -70,7 +71,7 @@ module ActiveModel full_message = message end - writable_symbols_and_messages_for(attribute) << [symbol, full_message] + writable_symbols_and_messages_for(attribute) << [symbol, full_message, partial_message] end end @@ -142,8 +143,8 @@ class Reform::Contract::Errors @store_new_symbols = true errors.keys.each do |attribute| - errors.symbols_and_messages_for(attribute).each do |symbol, message| - writable_symbols_and_messages_for(attribute) << [symbol, message] + errors.symbols_and_messages_for(attribute).each do |symbol, full_message, partial_message| + writable_symbols_and_messages_for(attribute) << [symbol, full_message, partial_message] end end end diff --git a/lib/api/errors/error_base.rb b/lib/api/errors/error_base.rb index 769b1b8804..8c6dc26ff8 100644 --- a/lib/api/errors/error_base.rb +++ b/lib/api/errors/error_base.rb @@ -77,7 +77,7 @@ module API errors.keys.each do |attribute| api_attribute_name = ::API::Utilities::PropertyNameConverter.from_ar_name(attribute) - errors.symbols_and_messages_for(attribute).each do |symbol, full_message| + errors.symbols_and_messages_for(attribute).each do |symbol, full_message, _| if symbol == :error_readonly api_errors << ::API::Errors::UnwritableProperty.new(api_attribute_name) else diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb index 659ca62468..ef71d44e59 100644 --- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb +++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb @@ -132,8 +132,11 @@ module Redmine # make the same symbol available on the customized object itself. # This is important e.g. in the API v3 where the error messages are # post processed. - cv.errors.symbols_for(attribute).each do |symbol| - errors.add(cv.custom_field.accessor_name.to_sym, symbol) + name = cv.custom_field.accessor_name.to_sym + cv.errors.symbols_and_messages_for(attribute).each do |symbol, _, partial_message| + # Use the generated message by the custom field + # as it may contain specific parameters (e.g., :too_long requires :count) + errors.add(name, partial_message, error_symbol: symbol) end end end