<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:refactormycode.com,2007:users309friends</id>
  <link type="application/atom+xml" href="http://refactormycode.com/users/309/friends" rel="self"/>
  <title>Elij friends</title>
  <updated>Sun Jan 13 21:10:09 +0000 2008</updated>
  <entry>
    <id>tag:refactormycode.com,2007:Code211</id>
    <published>2008-01-13T21:10:09+00:00</published>
    <updated>2008-01-14T16:49:49+00:00</updated>
    <title>[Ruby] A to Z only linking to letters with content</title>
    <content type="html">&lt;p&gt;I wanted A to Z anchor links at the top of the page to include the full alphabet but only to link when there is related content below. Can this be made better somehow?&lt;/p&gt;

&lt;pre&gt;## Controller
@a_to_z = Service.find(:all,:select=&amp;gt;'SUBSTR(name,1,1) AS letter',:group=&amp;gt;'SUBSTR(name,1,1)',:order=&amp;gt;'name').collect { |d| d.letter }


## View
&amp;lt;ul class=&amp;quot;pagination&amp;quot;&amp;gt;
&amp;lt;% for letter in 'A'..'Z' %&amp;gt;
	&amp;lt;li&amp;gt;&amp;lt;%= @a_to_z.index(letter) ? link_to(letter,:l=&amp;gt; letter) : content_tag(:a,letter,:class=&amp;gt;'f') %&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;% end %&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/pre&gt;</content>
    <author>
      <name>aubergene</name>
      <email>aubergene@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/211-a-to-z-only-linking-to-letters-with-content" rel="alternate"/>
  </entry>
</feed>
