alphabetical navigation

Hello,
I was thinking about doing an alphabetical navigation for i.e list of users (there would be alphabet at the top of the list and by clicking on a character the list would get filtered).
I did some googling but didn't find any plugin or quick hack sorting this problem out. It's however such a common thing that I was wondering whether there isn't really some.
Any suggestions or ideas are very welcome
Thanks
Jakub

Wow…

I was just finishing up something on just that topic. Let me know if this helps you and give me some feedback if you can!

http://www.napcsweb.com/howto/rails/aznavigation.pdf

maybe something like

view:

<% ('A'...'Z').each do |letter| -%>
<%= link_to letter, :controller => :user, :action => :list,
:starts_with => letter -%>
<% end -%>
<% @users.each do |user| -%>
  ...
<% end -%>

model:

class User < ActiveRecord::Base
  def find_by_last_initial(initial)
    # note: use of mysql db functions may not be portable
    find(:all, :conditions => ["UCASE(LEFT(last_name,1)) = ?", initial.upcase]
  end
end

controller:

class UserController < ApplicationController
  def list
    if params[:starts_with]
      @users = User.find_by_last_initial(params[:starts_with])
    else
      @users = user.find(:all)
    end
  end
end

Thank you very much Chris,

that’s exactly what I was dreaming about :wink:

Jakub

Chris Hall wrote:

Hello Brian,

I’m sorry I overlooked your post and implemented it by Chris’s
suggestion. I will try, however, to look at your writing and give you
some feedback.

Cheers

Jakub

Brian Hogan wrote: