SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Question - getting first field

    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"?

  2. #2
    Team ********* Louis Simoneau's Avatar
    Join Date
    Sep 2009
    Location
    Melbourne, Australia
    Posts
    228
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I'd use each_with_index instead of each, and then just test for i==0.

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or you could use:
    Code:
    baz == foo.bar.first

  4. #4
    SitePoint Member
    Join Date
    Jun 2010
    Location
    San Jose California
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes you can use the index of the object to get the desired result


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •