# Alphabetical navigation

**URL:** <https://www.ruby-forum.com/t/alphabetical-navigation/77770>\
**Category:** Rails\
**Created:** [November 30, 2006, 1:21pm UTC](https://www.ruby-forum.com/t/alphabetical-navigation/77770 "2006-11-30T13:21:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakub\_Kahovec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9c0ed/32.png) [@Jakub\_Kahovec](https://www.ruby-forum.com/u/Jakub_Kahovec)\
**Post date:** [November 30, 2006, 1:21pm UTC](https://www.ruby-forum.com/t/alphabetical-navigation/77770/1 "2006-11-30T13:21:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jakub\_Kahovec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9c0ed/32.png) [@Jakub\_Kahovec](https://www.ruby-forum.com/u/Jakub_Kahovec)\
**Post date:** [November 30, 2006, 4:26pm UTC](https://www.ruby-forum.com/t/alphabetical-navigation/77770/2 "2006-11-30T16:26:10Z")

</div>

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](http://www.napcsweb.com/howto/rails/aznavigation.pdf)

---

<div class="post-metadata">

**Author:** ![Jakub\_Kahovec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9c0ed/32.png) [@Jakub\_Kahovec](https://www.ruby-forum.com/u/Jakub_Kahovec)\
**Post date:** [November 30, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/alphabetical-navigation/77770/3 "2006-11-30T17:32:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jakub\_Kahovec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9c0ed/32.png) [@Jakub\_Kahovec](https://www.ruby-forum.com/u/Jakub_Kahovec)\
**Post date:** [November 30, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/alphabetical-navigation/77770/4 "2006-11-30T18:40:36Z")

</div>

Thank you very much Chris,  
that’s exactly what I was dreaming about 😉

Jakub

---

<div class="post-metadata">

**Author:** ![Jakub\_Kahovec](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9c0ed/32.png) [@Jakub\_Kahovec](https://www.ruby-forum.com/u/Jakub_Kahovec)\
**Post date:** [November 30, 2006, 7:26pm UTC](https://www.ruby-forum.com/t/alphabetical-navigation/77770/5 "2006-11-30T19:26:50Z")

</div>

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
