Permalink
Browse files

Issue #412 - Added support for :param_name to PaginatedCollection

Setting :param_name allows you to put multiple paginated collections
on a single page. (eg. Show action)
  • Loading branch information...
1 parent c6813b5 commit 1d3895a69f5f7a9bf3e26dd723dc9f6f0efbad78 @samvincent committed Aug 29, 2011
@@ -31,9 +31,11 @@ class PaginatedCollection < ActiveAdmin::Component
# @param [Hash] options These options will be passed on to the page_entries_info
# method.
# Useful keys:
- # :entry_name - The name to display for this resource collection
+ # :entry_name - The name to display for this resource collection
+ # :param_name - Parameter name for page number in the links (:page by default)
def build(collection, options = {})
@collection = collection
+ @param_name = options.delete(:param_name)
unless collection.respond_to?(:num_pages)
raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
@@ -64,7 +66,10 @@ def build_pagination_with_formats
end
def build_pagination
- text_node paginate(collection)
+ options = request.query_parameters.except(:commit, :format)
+ options[:param_name] = @param_name if @param_name
+
+ text_node paginate(collection, options)
end
# TODO: Refactor to new HTML DSL
@@ -8,12 +8,12 @@
posts = [Post.new(:title => "First Post"), Post.new(:title => "Second Post"), Post.new(:title => "Third Post")]
Kaminari.paginate_array(posts).page(1).per(5)
end
+
+ before do
+ request.stub!(:query_parameters).and_return({:controller => 'admin/posts', :action => 'index', :page => '1'})
+ end
context "when specifying collection" do
- before do
- request.stub!(:query_parameters).and_return({:controller => 'admin/posts', :action => 'index'})
- end
-
let(:pagination) do
paginated_collection(collection)
end
@@ -28,5 +28,22 @@
}.should raise_error(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.")
end
end
+
+ context "when specifying :param_name option" do
+ let(:collection) do
+ posts = 10.times.inject([]) {|m| m << Post.new }
+ Kaminari.paginate_array(posts).page(1).per(5)
+ end
+
+ let(:pagination) { paginated_collection(collection, :param_name => :post_page) }
+
+ before do
+ controller.params = {:controller => 'admin/posts', :action => 'index'}
+ end
+
+ it "should customize the page number parameter in pagination links" do
+ pagination.find_by_tag('div').last.content.should match(/\/admin\/posts\?post_page=2/)
+ end
+ end
end
end

0 comments on commit 1d3895a

Please sign in to comment.