我最近安装了will_paginate gem,它工作得很好,但我希望它能与我目前拥有的安装程序一起工作。现在我在同一页面上显示所有提要(或帖子),但它们是根据点击该页面的人数进行排序的:
controller.rb
@t = Time.now
@h1 = @t - 1.hour
@feeds = Feed.find(:all, :order => "created_at DESC").sort { |p1, p2| p2.impressionist_count(:filter=>:all, :start_date=>@h1) <=> p1.impressionist_count(:filter=>:all, :start_date=>@h1)}现在..。我测试了这个分页gem,如果我在控制器中这样做,它工作得很好:
controller.rb
@feeds = Feed.paginate(:per_page => 10, :page => params[:page], :order => "created_at DESC")所以我想到了1+1=2,并尝试通过以下方式将两者结合起来:
controller.rb
@feeds = Feed.paginate(:per_page => 10, :page=>params[:page], :order => "created_at DESC").sort { |p1, p2| p2.impressionist_count(:filter=>:all, :start_date=>@h1) <=> p1.impressionist_count(:filter=>:all, :start_date=>@h1)}我无法对我的帖子进行排序和分页。当我试图加载页面时,我得到一个错误:
#的未定义方法`total_pages
我希望它能工作,这将是非常甜蜜的:)。但是,如果它不起作用,有没有其他方法呢?
提前感谢!
发布于 2013-01-28 06:38:43
这是因为默认情况下,will_paginate只适用于ActiveRecord关系。一旦你使用了排序,它就会转换成一个数组。
require 'will_paginate/array' https://stackoverflow.com/questions/14552999
复制相似问题