Hello,
On 9 Mar 2007, at 17:06, Jonathan Linowes 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 Stewart
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---