ruby sinatra,postgres分页结果

时间:2013-09-05 13:40:44

标签: ruby postgresql sinatra sequel

我想要分页数据集。

Ruby代码是:

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"

1 个答案:

答案 0 :(得分:3)

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