gpt4 book ai didi

ruby-on-rails - will_paginate -error-undefined 方法 `total_pages'

转载 作者:行者123 更新时间:2023-12-04 15:26:35 24 4
gpt4 key购买 nike

我正在为我的 rails 应用程序使用 will_paginate "2.3.15"

在我的units_controller.rb

def index
@units = Unit.paginate(:all ,:page => params[:page], :order => 'created_at DESC')
end

in my views(index)

<%= will_paginate(@units)%>

but it gives error

undefined method `total_pages' for #<ActiveRecord::Relation:0xb523dc>

我的 rails 版本 3.0.0
和 ruby​​ 版本 1.8.7

请帮忙

最佳答案

为什么要添加:all ?
来自 will_paginate wiki你可能应该使用:

@units = Unit.paginate(:page => params[:page], :order => 'created_at DESC')

关于ruby-on-rails - will_paginate -error-undefined 方法 `total_pages',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6356062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com