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 %>


<%= @letter.succ %>


<% end %>

On Dec 15, 6:18 pm, edberner [email protected] wrote:

    <% 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

On Dec 15, 2007 9:18 PM, edberner [email protected] wrote:

<%= @letter = ‘a’ %>
<% end %>


http://www.jeremymcanally.com/

My books:
Ruby in Practice

My free Ruby e-book

My blogs:

http://www.rubyinpractice.com/

On Dec 16, 2007, at 12:47 AM, Jeremy McAnally wrote:

   <%= @letter.succ %>

<%= link_to h (school.title), new_school_course_path(school) %>
Ruby in Practice
Ruby in Practice

My free Ruby e-book
http://www.humblelittlerubybook.com/

My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/

Or a little fancier:

<% by_letter = @schools.group_by {|school| school.title[0,1]} -%>

<% ('A'..'Z').each do |letter| -%>
<%= letter %>
<% if by_letter.has_key?(letter) -%> <% by_letter[letter].sort.each do |school| -%>
<%= link_to h(school.title), new_school_course_path(school) %>
<% end -%> <% else -%>
(none)
<% end -%> <% end -%>

-Rob

Rob B. http://agileconsultingllc.com
[email protected]