How can I create a unique dom identifier for an html tag from a model

I have an index with multiple rows for items that have multiple attributes. I would like to update the contents of the items attribute with ajax, so I need a unique dom identifier. Is there a helper method? Now I am doing the following:

<span id="<%= item.id.to_s + "_on_storage"%>"> 

Best Phil

+6
source share
2 answers

you can use

 dom_id(item) 

What is the ActiveRecord method for generating DOM identifiers.

+20
source

It’s also good practice to use HTML5 data attributes:

 <span data-item-id="<%= item.id %>"> 
+3
source

Source: https://habr.com/ru/post/922165/


All Articles