user1903663
user1903663

Reputation: 1725

Sinatra, Kaminari pagination problems with SEQUEL and postgres

I am attempting to page a dataset with kaminari on Sinatra.

In my Gemfile I have

source "https://rubygems.org"
gem 'sinatra'
gem 'thin'
gem 'pg'
gem 'kaminari', :require => 'kaminari/sinatra'

The Ruby code is:

dataset = DB[:candidates] 
get '/candidate' do

     @items = dataset.order(:id).page(params[:page]).per(5)
     erb :candidate
end

and the error message is:

NoMethodError at /candidate
undefined method `page' for #<Sequel::Postgres::Dataset:0x94a6808>

    file: app.rb
    location: block in <main>
    line: 25

I am stuck. I have also tried will_paginate with similar frustration and failure.

Is the query correct? I have also tried:

@items = dataset.order("id").page(:page=>params[:page]).per(5)

which produces the same error.

Any ideas anybody?

Upvotes: 1

Views: 1022

Answers (2)

Andrew Hacking
Andrew Hacking

Reputation: 6366

In case someone else comes across this question, you can get pagination working in Sequel as follows without any additional gems:

Enable the extension:

DB.extension(:pagination)

Use the pagination extension (as per the question example):

page = Integer(params[:page]) rescue 1
@items = dataset.order(:id).paginate(page, 5)

Then its up to your view logic to render page links.

Upvotes: 3

ian
ian

Reputation: 12251

The README for Kaminari doesn't list Sequel as one of the supported ORMs.

You either need to use the Sequel pagination plugin or follow this gist to make your own Sequel extension.

Upvotes: 2

Related Questions