1

我想分页数据集。

红宝石代码是:

get '/candy' do
    @pagedata = { :cur_page => 1, :post_count => 0, :per_page => 3 }
    # set the current page to show
    @pagedata[:cur_page] = params[:page].to_i unless params[:page].nil?
    @cands = DB[:candidates] 
    #@cands = Post.by_created_at
    # set post_count
    @pagedata[:post_count] = DB[:candidates].count(:id)
    @cands = @cands.paginate(:page => @pagedata[:cur_page], :per_page => @pagedata[:per_page]) unless @cands.empty?
        erb :candy
    end

有什么问题?感谢所有帮助!

该行:

@cands = @cands.paginate(:page => @pagedata[:cur_page], :per_page => @pagedata[:per_page]) unless @cands.empty?

产生错误:

undefined method `paginate' for Sequel::Postgres::Dataset: "SELECT * FROM "candidates"
4

1 回答 1

3

您需要DB.extension(:pagination)在创建DB对象后添加。

于 2013-09-05T16:04:12.940 回答