Forum: Ruby on Rails adding a class in loops

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3e782285c43200b6bb25d830013018ca?d=identicon&s=25 Darren Pearce (limeyd)
on 2009-03-26 22:47
(Received via mailing list)
how do I only apply first to the first item?

<% @clients.each do |client| %>
   <%= link_to client.name, client, :class=> "first" %>
<% end %>

thanks
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2009-03-26 22:50
(Received via mailing list)
> how do I only apply first to the first item?
>
> <% @clients.each do |client| %>
>   <%= link_to client.name, client, :class=> "first" %>
> <% end %>

if client == @clients.first
....
end

Not super efficient though.

Why not use CSS?

http://www.w3schools.com/CSS/css_pseudo_classes.asp

-philip
This topic is locked and can not be replied to.