Allow dom_id method to accept multiple ids/models


This proposal is related to a “regression” I encountered today with turbo-rails.

hotwired/turbo-rails/pull/476 removed the ability to pass multiple ids/models to the turbo_frame_tag helper method. In that PR it was suggested that this ability be passed down to the dom_id method (which is a part of rails care) method rather than the turbo_frame_tag helper (which is a part of turbo-rails).

The proposed method could presumably look something like this:

article = 1)
comment = 1)

dom_id(article, comment)
# => "article_1_comment_1"

But I don’t think we could accept an unlimited amount of arguments while still preserving the current behavior regarding prefixes.

Currently the dom_id method accepts a prefix, which means method calls like the above result in a stringified representation of the ruby object.

dom_id(article, comment)
# => "#<Field:0x00000001179645c0>_article_1"


Would it make sense to make the first argument in the dom_id method accept an array (similar to the cache helper from ActionView)? This would preserve the backwards compatibility of prefixes.

dom_id([article, comment])
# => article_1_comment_1

dom_id([article, comment], :my_prefix)
# => my_prefix_article_1_comment_1

# Still backwards compatible
# => article_1

I’m happy to work on a PR, but I wanted to see if I could drum up some support. Thank you reading!

My proposal would still change the method signature for turbo_frame_tag, but I think it’s still a good trade-off.


<%= turbo_frame_tag article, comment do %>
  <!--- code -->
<% end %>


<%= turbo_frame_tag [article, comment] do %>
  <!--- code -->
<% end %>
1 Like

I made a PR: allow dom_id method to accept an array of records_or_classes by jwilsjustin · Pull Request #50608 · rails/rails · GitHub

Feedback welcomed!