我刚看到了will-paginate宝石。我试着把记录分成几页。我设法取得了一些进展,但遇到了一个问题。
分页选项卡(显示页码)出现在表的上方。它也是不受欢迎的。我怎样才能让标签出现在表下面。
这就是它目前的样子。
<= Previous 1 2 Next =>
Table Data我想让它看起来怎么样
Table Data
<= Previous 1 2 Next =>这是我的密码
<tbody>
<% g = Game.where(console: @title.split(' ').first(2).join(' ')).order(title: :asc).paginate(:page => params[:page], :per_page => 2) %>
<% g.each do |game| %>
<tr>
<td> <%= link_to "#{game.title}", game %></td>
<td> <%= game.genre %></td>
<td> <%= game.release_date %></td>
<td> <%= game.rating %></td>
<% if signed_in? && current_user.admin? %>
<div>
<td id = 'actions'><%= link_to 'Show', game, class: 'action' %></td>
<td id = 'actions'><%= link_to 'Edit', edit_game_path(game), class: 'action' %></td>
<td id = 'actions'><%= link_to 'Delete', game, method: :delete, class: 'action' %></td>
</div>
<% end %>
</tr>
<%= will_paginate g %>
<% end %>
</tbody>我甚至将will_paginate放在代码块的末尾。
发布于 2014-12-11 17:35:40
标记无效。您对will_paginate的调用在表中,在标记之间。
如果您希望它出现在下面、上面或任何其他地方,只需将调用放到页面中即可。
<%= will_paginate collection %>您确实应该在控制器中实例化实例变量。这条线不应该在你的视线里。
<% g = Game.where(console: # ...通过这种方式,您可以解决分页调用位置的限制,并编写更多的惯用Rails代码。
如果你必须走这条路,而我强烈地劝阻你,那就把你的收藏放在桌子上吧。
<% g = Game.where(console: @title.split(' ').first(2).join(' ')).order(title: :asc).paginate(:page => params[:page], :per_page => 2) %>然后,在此下面呈现分页,因为变量g现在存在:
<%= will_paginate g %>然后渲染你的桌子。
https://stackoverflow.com/questions/27428555
复制相似问题