Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

replacing using the base collection as this was incorrect with a filt…

…er in the form of a where clause
  • Loading branch information...
commit 23a4b7b03955016cc98e4a9ecfdd10ee17a8f05c 1 parent a7211d2
@zakgrant authored
View
6 lib/paginate_alphabetically/active_record.rb
@@ -8,10 +8,10 @@ def paginate_alphabetically(params)
end
module ClassMethods
- def pagination_letters(collection=nil)
+ def pagination_letters(filter=nil)
return ALL_LETTERS if @paginate_alphabetically__show_all_letters
- collection = collection.nil? ? all : collection
- collection.sort_by{|obj| obj.send(@attribute).upcase}.group_by {|group| group.send(@attribute)[0].chr.upcase}.keys
+ records = filter.nil? ? all : self.send(:where, filter)
+ records.sort_by{|obj| obj.send(@attribute).upcase}.group_by {|group| group.send(@attribute)[0].chr.upcase}.keys
end
def first_letter
View
2  lib/paginate_alphabetically/view_helpers.rb
@@ -5,7 +5,7 @@ def alphabetically_paginate(collection, options = {})
available_letters = PaginateAlphabetically::ALL_LETTERS
else
return "" if collection.empty?
- available_letters = collection.first.class.pagination_letters collection
+ available_letters = collection.first.class.pagination_letters options[:filter]
end
content_tag(:ul, safe(alphabetical_links_to(available_letters)),
:class => options[:class] || "pagination")
View
8 spec/paginate_alphabetically_spec.rb
@@ -15,18 +15,18 @@
Thing.paginate_alphabetically :by => :name, :show_all_letters => false
end
- context 'collection provided' do
+ context 'filter provided' do
before :each do
- @collection = %w(seven Eight Nine).map {|name| Thing.create!(:name => name)}
+ @filter = { :name => %w{one two} }
end
it 'picks out the correct letters from the set' do
- Thing.pagination_letters(@collection).should == %w{E N S}
+ Thing.pagination_letters(@filter).should == %w{O T}
end
it 'shows all letters always when asked' do
Thing.paginate_alphabetically :by => :name, :show_all_letters => true
- Thing.pagination_letters(@collection).should == ('A'..'Z').to_a
+ Thing.pagination_letters(@filter).should == ('A'..'Z').to_a
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.