Alphabet

What is the best way to do this?

A Andover
B Babson ...
C ...
. ...
. ...
. ...

<%= @letter = 'a' %>
  <% while @letter != 'z' %>
  <%= @letter %>
    <% for school in @schools %>
      <% if school.title.first == @letter %>
        <%= link_to h (school.title), new_school_course_path(school) %>
      <% end %>
    <% end %>
    <br/>
  <%= @letter.succ %>
  <br/>
  <% end %>

i think this:
http://agilewebdevelopment.com/plugins/alphabar

<%
('A'..'Z').each do |letter|
  this_letter = @schools.select {|school| school.title =~ /^#{letter}/}
%>
  <%= letter %>
  <% this_letter.each do |schools| %>
    <%= link_to h (school.title), new_school_course_path(school) %>
  <% end %>
<% end %>

That's just from memory, but it should work...

--Jeremy

Or a little fancier:

<% by_letter = @schools.group_by {|school| school.title[0,1]} -%>
<dl>
<% ('A'..'Z').each do |letter| -%>
   <dt><%= letter %></dt>
   <% if by_letter.has_key?(letter) -%>
     <% by_letter[letter].sort.each do |school| -%>
       <dd><%= link_to h(school.title), new_school_course_path(school) %><br /></dd>
     <% end -%>
   <% else -%>
     <dd style="color: grey;">(none)</dd>
   <% end -%>
<% end -%>
</dl>

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com