Rails: How to name and create unique divs within a loop?
Posted
by sscirrus
on Stack Overflow
See other posts from Stack Overflow
or by sscirrus
Published on 2010-06-16T20:20:06Z
Indexed on
2010/06/16
20:22 UTC
Read the original article
Hit count: 190
I have a view with a div that is looped many times. Each of the created divs need to have a unique ID so I can access them specifically (at the moment, all my divs have the same ID specified in html so whenever I try to access a specific div it just finds the first one).
This is the version that I currently have (multiple 'rowBox'es are not discernible).
<% @customers.each do |customer| %>
<div id="customer" class="rowBox">
...
</div>
<% end %>
I would like to be able to do something like:
<% @customers.each do |customer| %>
<div id="box<%=customer.id%>">
...
</div>
<% end %>
This doesn't seem to work. Any ideas on how to accomplish this?
© Stack Overflow or respective owner