我想分頁數據集。ruby sinatra,postgres分頁結果
的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"
在哪一行? –
對不起,我已經弄糟了這個。我再次編寫代碼,如果卡住了,我會重新發布,我期望這樣做。 – user1903663
確定尼古拉斯,我已更新並提供了您請求的信息。謝謝。 – user1903663