<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Flvorful Bloggage: Tag table</title>
    <link>http://blog.flvorful.com/articles/tag/table</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Quick Zebra Striping in Rails</title>
      <description>&lt;p&gt;Striping table rows is usually a necessity when making  accessible web pages.  This can be a tedious task. Through the ages (and by ages I mean the last 10 years or so) there have been many ways to do this in many dynamic languages.  Everything from taking the modulo of the index when iterating through the set, to flipping a counter back and forth.&lt;/p&gt;


	&lt;p&gt;Well, if you&amp;#8217;re programming in rails, you get a much easier way to do it via the &lt;code&gt;cycle&lt;/code&gt; method.  Let me show you how easy it is:&lt;/p&gt;


&lt;pre&gt;
&amp;lt;table&amp;gt;
  &amp;lt;% @objects.each do |obj| %&amp;gt;
  &amp;lt;tr class="&amp;lt;%= cycle("even", "odd") %&amp;gt;"&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;%= obj.id %&amp;gt;&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;%= obj.title %&amp;gt;&amp;lt;/td&amp;gt;
  &amp;lt;tr&amp;gt;
  &amp;lt;% end %&amp;gt;
&amp;lt;/table&amp;gt;
&lt;/pre&gt;

	&lt;p&gt;Simplicity itself.  Now as you loop through the set, it will cycle the class name of the row between &amp;#8220;even&amp;#8221; and &amp;#8220;odd&amp;#8221;.  Now all you need to do is set &lt;span class="caps"&gt;CSS&lt;/span&gt; values for those classes and your done.&lt;/p&gt;


Here is a quick example of a &lt;span class="caps"&gt;CSS&lt;/span&gt; class for odd:
&lt;pre&gt;
.odd{
    background:#dedede;
}
&lt;/pre&gt;

	&lt;p&gt;Gotta love rails.&lt;/p&gt;


	&lt;p&gt;&amp;#8212;jake&lt;/p&gt;</description>
      <pubDate>Sun, 12 Aug 2007 08:57:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:4744aa5a-2ceb-467b-8341-392155f1318d</guid>
      <author>jake</author>
      <link>http://blog.flvorful.com/articles/2007/08/12/quick-zebra-striping-in-rails</link>
      <category>Rails</category>
      <category>rails</category>
      <category>views</category>
      <category>cycle</category>
      <category>stripe</category>
      <category>table</category>
    </item>
  </channel>
</rss>
