我有以下代码
# 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[:page] 时,line @games = @presenter.games.paginate(params[:page], 5)
我得到params[:page]
了零。有谁知道为什么会这样?. 如果 page.blank 添加 page=1?只给我第一页的结果..有什么建议吗?