#<array:0x1041df24>的未定义方法`total_pages'

时间:2018-10-08 05:40:36

标签: ruby-on-rails-3 jruby will-paginate

我正在尝试对数组进行分页,但无法做到这一点。请帮助

以下是我的控制器代码:

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)

请有人帮忙

1 个答案:

答案 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]

方法