Forum: Ruby on Rails alpha pager?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jonathan L. (Guest)
on 2007-03-09 19:12
(Received via mailing list)
is there such thing as an alphabetical pager  helper or plugin?
or even a how-to article?
googling comes up empty for me
tia
linoj
Clayton C. (Guest)
on 2007-03-09 19:18
(Received via mailing list)
You mean sending/texting to pagers/phones?



http://en.wikipedia.org/wiki/SMS_gateways



has email addys for most carriers..





  _____

From: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] On Behalf Of Jonathan L.
Sent: Friday, March 09, 2007 9:07 AM
To: removed_email_address@domain.invalid
Subject: [Rails] alpha pager?



is there such thing as an alphabetical pager  helper or plugin?

or even a how-to article?

googling comes up empty for me

tia

linoj
Andrew S. (Guest)
on 2007-03-09 20:09
(Received via mailing list)
Hello,

On 9 Mar 2007, at 17:06, Jonathan L. wrote:
> is there such thing as an alphabetical pager  helper or plugin?
> or even a how-to article?
> googling comes up empty for me

Assuming you're after a way of paginating by first letter, here are a
few lines of code which I wrote to do this:

routes.rb:

   map.customers 'customers/:letter', :controller =>
'customers', :letter => /[a-zA-Z]/

customers_controller.rb:

   def index
     # Paginate alphabetically by surname.
     if params[:letter] =~ /^[A-Z]$/i
       letter = params[:letter].upcase
     else
       letter = 'A'
     end
     @customers = Customer.all_by_name "contacts.last_name like '#
{letter}%'"    # My customers table is joined to my contacts table
   end

customers_helper.rb:

   def glossary_index(params)
     result = "<p class='glossary-index'>"
     ('A'..'Z').to_a.each { |letter|
       result << link_to_unless_current(letter, url_for(params.merge
(:letter => letter))) {
         "<span>#{letter}</span>"
       }
     }
     result << '</p>'
   end

stylesheet.css:

   p.glossary-index a    { margin: 0.6em; }
   p.glossary-index span { margin: 0.6em; }

index.rhtml:

   <%= glossary_index :controller => 'customers' %>

   <% for customer in @customers %>
     ...
   <% end %>


Hope that helps.

Regards,
Andy S.
This topic is locked and can not be replied to.