分组项目的分页

时间:2018-03-23 15:13:27

标签: ruby-on-rails

我有一个问题,分页不适用于按天项目分组的Will_paginate gem(我的代码中的“游戏”)。

以下是我的观点:

<div>

<% @game_days.each do |day, games| %>

<% for game in games %>

<%= game.game_name %>
<%= game.game_description %>
<%= image_tag avatar_url(game.user) %>

<% end %>

<% end %>

<%= will_paginate @game_days %>

 </div>

我的控制器(工作):

class PagesController < ApplicationController
  def home
    @games = Game.all
    @game_days = Game.paginate(:page => params[:page], :per_page => 10).order("created_at DESC").group_by { |g| g.created_at.strftime("%B, %d") }
end

ERROR

The @pages variable appears to be empty. Did you forget to pass the collection object for will_paginate?

干杯!

1 个答案:

答案 0 :(得分:0)

在你的控制器中试试这个:

@game_days = @games.page(:page => params[:page], :per_page => 10)
                   .order("created_at DESC")
                   .group_by { |g| g.created_at.strftime("%B, %d")