 <p>The problem is that @flits is nil, presumably because your all_flits method is returning nil.</p> <p>However, I'd recommend not putting that logic in the view, breaking up a tag like that. You have several options to make it cleaner:</p> <hr> <p>Option 1: Use the CSS pseudo-class <code>first-child</code> like so:</p> <pre><code> li:first-child { ... } </code></pre> <p>This has the advantage of not requiring any back-end logic or special markup. The only downside is that it has spotty older browser support, e.g. IE6.</p> <hr> <p>Option 2: Use the Rails tag helpers.</p> <pre><code>&lt;%= content_tag :li, :class =&gt; @flits.first==flit?"first":"" %&gt; </code></pre> <hr> <p>Option 3: Tuck it away in a helper method</p> <pre><code>&lt;%= li_for_flit %&gt; </code></pre> <p>Then in the helper:</p> <pre><code>def li_for_flit #spit out your tag here end </code></pre>