Extend dom_id and dom_class to accept var-args - #44081
Conversation
b105e51 to
814b048
Compare
p8
left a comment
There was a problem hiding this comment.
Hi @seanpdoyle 👋 , I think this would be a nice addition.
|
@seanpdoyle Can you squash the commits? |
Changes `dom_id` and `dom_class` to accept a variable set of prefixes: ```ruby dom_class @post, :first_prefix, :second_prefix # => "first_prefix_second_prefix_post" dom_class @post, [:first_prefix, :second_prefix] # => "first_prefix_second_prefix_post" dom_id @post, :first_prefix, :second_prefix # => "first_prefix_second_prefix_post_123" dom_id @post, [:first_prefix, :second_prefix] # => "first_prefix_second_prefix_post_123" ``` These changes align with the [FormBuilder#field_id][] interface, which accepts multiple `suffixes` arguments. [field_id]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-field_id
95edbd6 to
ed6ce19
Compare
|
Thanks @seanpdoyle ! |
|
I think these methods have gone for many years with only a single argument prefix. What's the change or use case that necessitates adding this now? Is there a suitable workaround that users could add in their apps for the multiple prefix version? E.g. doing the concatenation at the call-sites? I'm leaning towards closing this as is. |
|
That's sensible. Closing. |
I think Turbo-Rails is something relatively new that significantly increases the demand for generating matching identifiers that exist across Views and application code. For example, Turbo Broadcast targets.
The main benefit of handling multi-value prefixes inside of |
|
@seanpdoyle Here's an idea. if the modification of these methods are objectionable, what do you think of proposing a new method like Edit: I'll make a quick PR to propose. |
|
Let's see how it goes: #55204 |
|
I wouldn't necessarily consider my comments from 3 years ago to still be valid. I hadn't thought of the case with turbo-rails putting more strain on While That said, I don't have any merge rights on here anymore. So it's up to someone else. |
Summary
Changes
dom_idanddom_classto accept a variable set of prefixes:These changes align with the FormBuilder#field_id interface, which
accepts multiple
suffixesarguments.