will_paginate -错误未定义方法“total_pages”

2024-02-02

我正在为我的 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 和红宝石版本1.8.7

plz help


为什么要添加:all? 来自will_paginate 维基 https://github.com/mislav/will_paginate/wiki你可能应该使用:

@units = Unit.paginate(:page => params[:page], :order => 'created_at DESC')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

will_paginate -错误未定义方法“total_pages” 的相关文章

随机推荐