fix: edit_component field_name signature

field_name is called by
actionview-7.0.4.2/lib/action_view/helpers/tags/base.rb who pass 3
arguments. We need to be compliant in order to make it valid.

We reuse the same method signature with nil default values as those
params are not being used.
This commit is contained in:
Nicolas Cavigneaux 2023-03-13 09:09:20 +01:00 committed by Colin Darie
parent db71323b92
commit f78b415c51
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 1 additions and 40 deletions

View file

@ -93,7 +93,7 @@ class Attachment::EditComponent < ApplicationComponent
nil nil
end end
def field_name def field_name(object_name = nil, method_name = nil, *method_names, multiple: false, index: nil)
helpers.field_name(@form_object_name || ActiveModel::Naming.param_key(@attached_file.record), attribute_name) helpers.field_name(@form_object_name || ActiveModel::Naming.param_key(@attached_file.record), attribute_name)
end end

View file

@ -1,39 +0,0 @@
module FormTagHelper
# from Rails 7 ActionView::Helpers::FormTagHelper
# https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-field_id
# Should be removed when we upgrade to Rails 7
def field_id(object_name, method_name, *suffixes, index: nil, namespace: nil)
if object_name.respond_to?(:model_name)
object_name = object_name.model_name.singular
end
sanitized_object_name = object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").delete_suffix("_")
sanitized_method_name = method_name.to_s.delete_suffix("?")
[
namespace,
sanitized_object_name.presence,
(index unless sanitized_object_name.empty?),
sanitized_method_name,
*suffixes
].tap(&:compact!).join("_")
end
# from Rails 7 ActionView::Helpers::FormTagHelper
# https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-field_name
# Should be removed when we upgrade to Rails 7
def field_name(object_name, method_name, *method_names, multiple: false, index: nil)
names = method_names.map! { |name| "[#{name}]" }.join
# a little duplication to construct fewer strings
case
when object_name.blank?
"#{method_name}#{names}#{multiple ? "[]" : ""}"
when index
"#{object_name}[#{index}][#{method_name}]#{names}#{multiple ? "[]" : ""}"
else
"#{object_name}[#{method_name}]#{names}#{multiple ? "[]" : ""}"
end
end
end