ruby on rails 3 - will_paginate not working with arrays -
i've added
# config/initializers/will_paginate_array_fix.rb require 'will_paginate/array' but still not seem getting pagination support arrays, eg:
def index @array = (1..100).to_a.paginate(params[:page]) end # gives typeerror: can't convert symbol integer it works fine models, , get
defined? willpaginate # => constant activerecord::base.respond_to? :paginate # => true # but: array.respond_to? :paginate # => false anyone know missing pagination support arrays?
found answer looking @ source code in will_paginate/array:
def paginate(options = {}) page = options[:page] || 1 per_page = options[:per_page] || willpaginate.per_page total = options[:total_entries] || self.length willpaginate::collection.create(page, per_page, total) |pager| pager.replace self[pager.offset, pager.per_page].to_a end end so arrays, have use .paginate (not .page), , have pass hash. following works:
def index @array = (1..100).to_a.paginate(page: params[:page]) end
Comments
Post a Comment