Alphabetize pagination

Note I have not tried anything about my question, nor Googled
anything about it yet, I was just wondering if this was possible, so
if you wanna answer with lmgtfy, rtfm, or anything like that, please
get it out of the way immediately.

I have a simple address book app that I want to sort by last name, and
put each letter on a different page. Can the Paginate Gem be
customized this much, that is, to provide pagination by, let’s say
record.last_name, and instead of page numbers, show A…Z instead?

Not that I know of, or have done… but I haven’t investigated the

As an alternative, you could put a series of letter links at the top of
your table (or down a side; images or CSS styled so they look nice)
which filter your records by that letter, and leave the will_paginate
gem as is to paginate the table body using all the filtered entries
returned from the query.

This is for a glossary that I setup …

class Glossary
def self.find_glossaries(options = {})
if options[:category].blank?
paginate :per_page => options[:per_page], :page => options
:conditions => [“term LIKE ?”, options[:letter]+"%"], :order
=> “term”

Then in the controller
@letter = params[:letter].blank? ?
@category.glossaries.collect.first.term.first.upcase : params[:letter]
@glossaries = @category.glossaries.find_glossaries(:letter =>
@letter, :page => params[:page])

There is more to this but the the important one is the model

And then this view helper:

def letter_options(category=nil)
if category.nil?
@letter_options_list = Glossary.all.collect!{|c|
c.term.first.upcase }.uniq.sort!
@letter_options_list = category.glossaries.collect!{|c|
c.term.first.upcase }.uniq.sort!

I hope this get you going…

And I also made it all work via ajax using this simple railscast:

Here’s how I implemented something similar.

On the index page of my contacts, I list them alphabetically by
default, paginated with 10 per page. At the top of this index page, I
spit out the alphabet with each letter having it’s own link. Click
any letter and I return all the contacts whose last name starts with
that letter, paginated 10 per page of that letter. I also add some
css styling to the letter they clicked to show which letter they’re
on. Hope that helps.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs