Fix crash on attributes with interpolation arguments

The application crashed when we generated hints to attributes with
interpolation arguments in their `human_attribute_name`.

When generating the hint, we used the `custom_label` method to generate
a label and get the `for` attribute and, since we weren't passing a
text, it used the default human attribute name for the field. However,
it crashes if the default attribute name requires an interpolation
argument.

So now, since we were only using the `custom_label` method in order to
get the `for` attribute, we're simply passing an arbitrary text to the
method.
This commit is contained in:
Javi Martín
2022-03-25 15:23:09 +01:00
parent d719b2291e
commit 1fa05b1f54
2 changed files with 13 additions and 1 deletions

View File

@@ -83,7 +83,7 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
def help_text_id(attribute, options)
if options[:hint].present?
"#{custom_label(attribute, nil, nil).match(/for="([^"]+)"/)[1]}-help-text"
"#{custom_label(attribute, "Example", nil).match(/for="([^"]+)"/)[1]}-help-text"
end
end
end