# Help with paginate, collection.size error?!

**URL:** <https://www.ruby-forum.com/t/help-with-paginate-collection-size-error/84321>\
**Category:** Rails\
**Created:** [February 3, 2007, 2:01am UTC](https://www.ruby-forum.com/t/help-with-paginate-collection-size-error/84321 "2007-02-03T02:01:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mixplate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mixplate](https://www.ruby-forum.com/u/mixplate)\
**Post date:** [February 3, 2007, 2:01am UTC](https://www.ruby-forum.com/t/help-with-paginate-collection-size-error/84321/1 "2007-02-03T02:01:05Z")

</div>

hi, i am trying to pass the paginate\_collection function this.

@pages, @viewObj = paginate\_collection Mcategory.find(params[:id],  
:include =\> {:scategories =\> :howtos}), :page =\> @params[:page]

however, the problem seems that this format cant be read into the  
collection.size method.

NoMethodError (undefined method `size' for #<Mcategory:0x22b0c84>): /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/base.rb:1792:in`method\_missing’

but when i try with a simple collection call of find(:all), it works  
fine. so i am guessing it doesnt like my include statement.

---

<div class="post-metadata">

**Author:** ![mixplate](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mixplate](https://www.ruby-forum.com/u/mixplate)\
**Post date:** [February 3, 2007, 2:25am UTC](https://www.ruby-forum.com/t/help-with-paginate-collection-size-error/84321/2 "2007-02-03T02:25:19Z")

</div>

i am using this…

def paginate\_collection(collection, options = {})  
logger.debug "----~CALLING PAGIONATE!!!== "  
default\_options = {:per\_page =\> 5, :page =\> 1}  
options = default\_options.merge options

pages = Paginator.new self, collection.size, options[:per\_page],  
options[:page]  
#pages = Paginator.new self, 50, options[:per\_page], options[:page]

first = pages.current.offset  
last = [first + options[:per\_page], collection.size].min  
#last = [first + options[:per\_page], 50].min

```
slice = collection[first...last]
return [pages, slice]

```

end
