因此,我在网络应用程序上更新了 Heroku 堆栈,并使用 ruby 3.2.2 和 will_paginate 4.0,但现在在我的分页页面之一上收到错误。我收到的具体错误是
2023-06-15T00:33:11.759517+00:00 app[web.1]: Rendered users/index.html.erb within layouts/application (Duration: 2.6ms | Allocations: 1025)
2023-06-15T00:33:11.759543+00:00 app[web.1]: Rendered layout layouts/application.html.erb (Duration: 2.7ms | Allocations: 1069)
2023-06-15T00:33:11.759701+00:00 app[web.1]: Completed 500 Internal Server Error in 7ms (ActiveRecord: 2.5ms | Allocations: 2352)
2023-06-15T00:33:11.760282+00:00 app[web.1]:
2023-06-15T00:33:11.760282+00:00 app[web.1]: ActionView::Template::Error (wrong number of arguments (given 4, expected 3)):
2023-06-15T00:33:11.760282+00:00 app[web.1]: 13: <h3><%= link_to "Create New Dude", new_user_path %></h3>
2023-06-15T00:33:11.760283+00:00 app[web.1]: 14: <% end %>
2023-06-15T00:33:11.760283+00:00 app[web.1]: 15:
2023-06-15T00:33:11.760284+00:00 app[web.1]: 16: <%= will_paginate %>
2023-06-15T00:33:11.760284+00:00 app[web.1]: 17:
2023-06-15T00:33:11.760284+00:00 app[web.1]: 18: <table>
2023-06-15T00:33:11.760284+00:00 app[web.1]: 19: <thead>
2023-06-15T00:33:11.760284+00:00 app[web.1]:
2023-06-15T00:33:11.760285+00:00 app[web.1]: app/views/users/index.html.erb:16
实际代码是
<%= will_paginate %>
<table>
<thead>
<th></th> <!-- Icon -->
... a bunch of stuff you don't need to see ...
</thead>
<tbody>
<%= render @users %>
</tbody>
</table>
<%= will_paginate %>
我在 will_paginate 4.0 上找不到任何明确的文档来说明为什么会抛出
wrong number of arguments (given 4, expected 3)
的特定错误。我唯一能找到的是这里使用的新的基本 will_paginate https://github.com/mislav/will_paginate。我是否需要以某种方式将我用来分页的表格捆绑到一个新的结构中?
任何帮助将不胜感激。
新版本的
will_paginate
不再将选项哈希作为第三个参数。相反,所有选项都应作为关键字参数传递。所以,你的代码应该更改为:
<%= will_paginate @users, per_page: 10 %>
<table>
<thead>
<th></th> <!-- Icon -->
... a bunch of stuff you don't need to see ...
</thead>
<tbody>
<%= render @users %>
</tbody>
</table>
<%= will_paginate @users, per_page: 10 %>
per_page
选项用于指定每页应显示多少条记录。在本例中,我们将其设置为 10。
您还可以将其他选项作为关键字参数传递给
will_paginate
。例如,您可以传递 renderer
选项来指定自定义分页渲染器。