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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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>):
    /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.
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 = 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
This topic is locked and can not be replied to.