【发布时间】:2018-10-08 05:40:36
【问题描述】:
我正在尝试对数组进行分页,但无法这样做。请帮忙
以下是我的控制器代码:
require 'will_paginate/array'
class AccountsController < ApplicationController
def children
@account = @rest_resource
@children = []
User.find_all_by_parentId(@account.user.id).paginate(:page
=> params[:page], :per_page => 10).each { |eu|
u = eu.user
ent = Table2.find(u.login)
@children << ent unless ent.nil?
}
end
end
查看文件 -> children.html.erb:
<%= will_paginate @children %>
<table>
<%= render :partial => 'account', :collection => @children %>
</table>
部分视图->_account.html.erb:
<tr class="<%= cycle('even', 'odd') %> <% if account.user.is_test? %>Test<% end %>">
<td><strong><%= link_to h(account.login), account_path(account) %></strong></td>
<td><% if account.user.test? %>Test <% end %><%= account.attr2 %></td>
<td>
<strong><%= account.companyName %></strong><br/>
<%= account.contact %> - <%= account.Email %> - <%= account.Mobile %>
</td>
<td><%=h account.Status %></td>
</tr>
这不起作用。它说:
undefined method `total_pages' for #<Array:0x1041df24>
Rails 版本:
Rails 3.2.13
JRuby 版本:
jruby 9.1.17.0 (2.3.3)
我的应用正在使用:
will_paginate (3.0.4)
请有人帮忙解决这个问题
【问题讨论】:
-
请任何人帮忙。
-
能否指定使用total_pages方法的代码
标签: ruby-on-rails-3 jruby will-paginate