我想调出一个数据集。
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"
最佳答案
创建DB.extension(:pagination)
对象后,需要添加DB
。
关于ruby - ruby sinatra,Postgres分页结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18637966/