Reputation: 1368
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>
Upvotes: 4
Views: 2427
Reputation: 188
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' %>
Upvotes: 4
Reputation: 10111
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>
Upvotes: 1