numerica — 2010-09-10T16:47:49-04:00 — #1
Hey, I have a question.
I am loading up radio buttons in a form based from db. I want the first radio button that shows up to be selected. For simple demo I am just going to use <li>s.
<% foo.bar.each do |baz| %>
<li><%= baz.bleh %></li>
<% end %>
In that example how do I make the first <li> have class="first"?
louis_simoneau — 2010-09-14T22:15:12-04:00 — #2
I'd use each_with_index instead of each, and then just test for i==0.
andolasoft — 2010-10-20T10:49:45-04:00 — #3
yes you can use the index of the object to get the desired result
reggieb — 2010-09-29T16:31:53-04:00 — #4
Or you could use:
baz == foo.bar.first