1
我有以下代碼PARAMS [:頁面]爲零
# Gemfile
gem 'will_paginate'
# /config/initializers/will_paginate_array.rb
require 'will_paginate/collection'
Array.class_eval do
def paginate(page = 1, per_page = 15)
WillPaginate::Collection.create(page, per_page, size) do |pager|
pager.replace self[pager.offset, pager.per_page].to_a
end
end
end
# /app/controllers/games_controller.rb
def show
@presenter = GamesPresenter.new(json)
@games = @presenter.games.paginate(params[:page], 5)
end
# /app/views/games/index.html.erb
<% @games.each do |game| %>
...
<% end %>
<%= will_paginate @games %>
然而
當我試圖通過PARAMS [:頁面]在line @games = @presenter.games.paginate(params[:page], 5)
我得到params[:page]
是零。有誰知道爲什麼會出現這種情況? 。如果添加page = 1,如果page.blank?只給我第一頁結果..請提出任何建議?
謝謝你的回覆...但同樣它只是給我的第一個結果集的和不斷變化的頁面只是拆分這些結果。 {例如,在我的情況下,我只獲得了前100個結果,其餘的都不會來}。你知道爲什麼嗎? – 2013-03-12 15:17:25
我可以問你想達到什麼嗎?你想分頁陣列(基於初始化文件的文件名) – jvnill 2013-03-12 15:19:58
耶一樣的...所以我不知道爲什麼我只得到第一個100分的結果通過搜索......但沒有will_paginate我得到的更多。 。 – 2013-03-12 15:23:35