Forum: Ruby on Rails help with paginate, collection.size error?!!

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
mixplate (Guest)
on 2007-02-03 03:01
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>):

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.
mixplate (Guest)
on 2007-02-03 03:25
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 = self, collection.size, options[:per_page],
   #pages = 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]
This topic is locked and can not be replied to.