Master ruby with us

‘cycle’ css-related feature of Rails

Posted by firstruby on January 14, 2009

If you want to display the list ( of users ) with different css-class for alternate record, there is no need to check the odd-even records,

For this, Rails have awesome feature and that is – ‘cycle’

We can use this as,

say we have 2 css classes-blank and white. If want to apply ‘black’ and ‘white’ class for alternate user record, then we have to write the code as,

<% @users.each do |user| %>
<li class="<%= cycle('black', 'white') -%>">
<%= %></li>
<% end %>

Cool feature 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: