【问题标题】:Trouble with will_paginate methodwill_paginate 方法有问题
【发布时间】:2019-09-07 13:45:43
【问题描述】:

我正在尝试在我的 rails 应用程序中使用 will_paginate 进行分页。我正在关注 Michael Hartl 的 Rails 教程。 在我的控制器中,我有

def index
  @users = User.paginate(page: params[:page])
end

在我看来我有

<%= will_paginate %>
<ul class="users">
  <% @users.each do |user| %>
    <li>
      <%= gravatar_for user, size: 50 %>
      <%= link_to user.name, user %>
    </li>
  <% end %>
</ul>
<%= will_paginate %>

它抛出以下错误:will_paginate 的参数数量错误(给定 0,预期为 1)

【问题讨论】:

    标签: ruby-on-rails will-paginate


    【解决方案1】:

    遇到同样的问题。

    更改为 3.1.7(从 Gemfile 中的 3.1.6)为我修复了它。

    参考。 ArgumentError: wrong number of arguments (given 0, expected 1) #589

    【讨论】:

      【解决方案2】:

      我遇到了这个问题,我浏览了一些时间来获得解决方案,我得到的确切错误是:

      enter image description here

      解决方案

      转到 gemfile 并将 gem 'will_paginate','3.1.6' 更改为 gem 'will_paginate','3.1.7'

      然后去终端输入bundle update

      然后将分页将起作用

      enter image description here

      【讨论】:

        【解决方案3】:

        我在不同的版本上遇到了同样的问题。

        对于我的情况,从3.1.8 更改为3.3.0 的最新版本解决了这个问题。

        顺便说一句,我使用的是 Rails 6.1.1

        【讨论】:

          【解决方案4】:

          在 Gemfile 中:gem 'will_paginate', '~&gt; 3.1' 在其他文件中:&lt;%= will_paginate @articles%&gt;

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-03-22
            • 2011-09-15
            • 2023-03-28
            • 2015-08-28
            • 2011-11-08
            • 2010-11-27
            • 1970-01-01
            相关资源
            最近更新 更多