我正在尝试对数组进行分页,但无法做到这一点。请帮助
以下是我的控制器代码:
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 3.2.13
JRuby版本:
jruby 9.1.17.0 (2.3.3)
我的应用正在使用:
will_paginate (3.0.4)
请有人帮忙
答案 0 :(得分:0)
您正在将@children初始化为数组,并将其传递给will_paginate,这样它会抛出错误...尝试像
那样传递from mlxtend.plotting import stacked_barplot
fig= stacked_barplot(df,rotation=45,legend_loc='best')
fig.text(??)
fig.show()
如果您想传递该数组中的每个实例,请使用
will_paginate @children[0]
方法