How can I generate a unique dom id for a html tag from model

▼魔方 西西 提交于 2019-12-07 02:38:17

问题


I am having an index view with several rows for items which have multiple attributes. I would like to update the content of an items attribute with ajax, therefore I need a unique dom id. Is there a helper method available? What I am doing right now is:

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

Best, Phil


回答1:


You can use

dom_id(item)

Which is an ActiveRecord method for generating DOM IDs.




回答2:


A good practice as well is to use HTML5 data attributes:

<span data-item-id="<%= item.id %>">


来源:https://stackoverflow.com/questions/11817398/how-can-i-generate-a-unique-dom-id-for-a-html-tag-from-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!