It would not be too difficult to create at all, for example, if you had find , it could be like:
@all_words = Word.select("words.word")
... which returned the result in a result set, such as a list of words like this:
["alphabet", "boy", "day", "donkey", "ruby", "rails", "iPad"]
... you could do this:
@all_words.collect {|word| word[0,1]}.uniq.sort
who will return:
["a", "b", "d", "r", "i"]
.collect {|word| word[0,1]} .collect {|word| word[0,1]} saves the first letter of each word into a new array, and uniq filters out unique letters and sort sorts them alphabetically.
Just assign it to a variable, and you can use it in your view like this:
<ul> <% @first_letters.each do |letter| %> <%= content_tag :li, link_to(letter, words_pagination_url(letter), :title => "Pagination by letter: #{letter}") %> <% end %> </ul>
Then your controller action can decide what to do with the parameter from the pagination, if it is passed:
def index if params[:letter] @words = Word.by_letter(params[:letter]) else @words = Word.all end end
And then the area in your model will look something like this:
scope :by_letter, lambda { |letter| { :conditions => ["words.word LIKE ?", "#{letter}%"] }}
Your routes require something like:
match "words(/:letter)" => "words#index", :as => words_pagination
I have not tested this completely, but it should set you on the right path.