4

I'm having a bit problem on how to get Kaminari work. I did the installation procedure in GitHub.

gem "kaminari"

Then run

bundle

I have this snippet for index

@users = User.order("name")

I added this on my view

<%= paginate @users %>

Then I got this error.

undefined method `paginate' for #<#<Class:0x00000102934330>:0x00000102932508>

Did I missed something? I also tried to include the page method

@users = User.order("id").page(1)

But I get this error instead

undefined method `page' for #<ActiveRecord::Relation:0x000001017d0300>
Ben
  • 1,370
  • 17
  • 42

2 Answers2

4

include kaminari and bootstrap-kaminari-views gems in your project Gemfile,

gem "kaminari"

gem "bootstrap-kaminari-views"

Execute bundle install in terminal,

$ bundle install

In products_controller.rb,

@products = Product.order("name")

@products = Kaminari.paginate_array(@products).page(params[:page]).per(5)

In products/index.html.erb,<%= paginate @products, :theme => 'twitter-bootstrap-3' %>

Prashant Kumar
  • 20,069
  • 14
  • 47
  • 63
Sasi
  • 188
  • 1
  • 13
1

take a look at the railscast for kaminari its really nice http://railscasts.com/episodes/254-pagination-with-kaminari

bash rails g kaminari:views default

products_controller.rb

@products = Product.order("name").page(params[:page]).per(5)

products/index.html.erb

<%= paginate @products %>

app/views/kaminari/_prev_span.html.erb

<span class="prev disabled"><%= raw(t 'views.pagination.previous') %></span>
MZaragoza
  • 10,108
  • 9
  • 71
  • 116