张贴这个问题,我试图从一个类似的问题在这里该解决方案之前:
will_paginate function not rendering page links
will_paginate没有显示链接
代替< - 1 2 3 ... N - >,我看到消息“获取更多产品......“。
//控制器
1. @posts是ActiveRecord的::关系
2. 6记录作为结果,因此,期待
@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 %>
3页
对于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'