[英]will_paginate doesn't show links
在發布此問題之前,我在這里嘗試了類似問題的解決方案:
will_paginate函數不呈現頁面鏈接
我看到的是“正在獲取更多產品...”,而不是<-1 2 3 ... N->。
//控制器
1. @posts是ActiveRecord :: Relation
2. 6條記錄為結果,因此需要3頁
@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)
//查看
<% @posts.each do |post| %>
...
...
<%end%>
<%= will_paginate @posts %>
對於http://localhost:3000/?page=1
我看到“正在獲取更多產品...”
對於http://localhost:3000/?page=2
也“正在獲取更多產品...”
但是對於http://localhost:3000/?page=3
我看到←上一頁1 2 3下一頁→。 為什么只在最后一頁上分頁?
我正在使用RoR 4.0.0
Gemfile: gem 'will_paginate', '~> 3.0.5'
它應該是
@posts = @ posts.paginate(params [:page],每頁:2)
快速瀏覽http://skatara.blogspot.com/2015/02/pagination-in-rails-using-willpaginate.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.