2013-11-04 176 views
2

張貼這個問題,我試圖從一個類似的問題在這裏該解決方案之前:
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' 

回答