Reputation: 10496
Before posting this question i tried this solution from a similar question here:
will_paginate function not rendering page links
Instead of <- 1 2 3 ... N ->, I see the message "Fetching more products...".
// controller
1. @posts are ActiveRecord::Relation
2. 6 record as results, so expecting 3 pages
@posts = User.joins(entries: [{storage: :vote}, :category])
.where("votes.count > ?", 0)
.select("users.username AS username,
storages.id AS storage_id,
storages.title AS title,
storages.content AS content,
votes.count AS votes,
categories.category_name AS category_name")
.order("votes.count DESC")
@posts = @posts.page(params[:page]).per_page(2)
// view
<% @posts.each do |post| %>
...
...
<%end%>
<%= will_paginate @posts %>
For http://localhost:3000/?page=1
i see "Fetching more products..."
for http://localhost:3000/?page=2
also "Fetching more products..."
but for http://localhost:3000/?page=3
i see ← Previous 1 2 3 Next →.
Why pagination only on last page?
I'm using RoR 4.0.0
Gemfile: gem 'will_paginate', '~> 3.0.5'
Upvotes: 2
Views: 810
Reputation: 758
it should be
@posts = @posts.paginate(params[:page], per_page: 2)
for quick look http://skatara.blogspot.com/2015/02/pagination-in-rails-using-willpaginate.html
Upvotes: 0