gpt4 book ai didi

ruby-on-rails - will_paginate未定义方法 `total_pages'

转载 作者:行者123 更新时间:2023-12-03 05:39:59 25 4
gpt4 key购买 nike

我在这里缺少什么?我正在使用 haml_scaffold 生成器,并且页面与 will_paginate 一起工作正常。当我开始修补时,我最终遇到了这个“total_pages”错误,并且我不确定我在做什么导致了它。有人有任何见解吗?我正在使用mislav-will_paginate 2.3.11。

mike@jauntyjackalope:~/project$ script/console
Loading development environment (Rails 2.3.4)
>> @locations = Location.find_all_by_city("springfield")
=> [#<Location id: 3, address: "123 Main St", city: "springfield", phone: "321-1234", business_id: 2>]
>> @locations.class
=> Array
>> @locations.collect{|loc| loc.business}
=> [#<Business id: 2, name: "A Bar", website: "www.abar.com", business_owner_id: 1, created_at: "2009-08-31 21:13:10", updated_at: "2009-08-31 21:13:10">]
>> @locations.class
=> Array
>> @locations.paginate(:page => 1, :per_page => 2)
=> [#<Location id: 3, address: "123 Main St", city: "springfield", phone: "321-1234", business_id: 2>]
>> helper.will_paginate(@locations)
NoMethodError: undefined method `total_pages' for #<Array:0xb6f83bc4>
from /var/lib/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/view_helpers.rb:197:in `total_pages_for_collection'
from /var/lib/gems/1.8/gems/mislav-will_paginate-2.3.11/lib/will_paginate/view_helpers.rb:98:in `will_paginate'
from (irb):7

>> y @locations
---
- !ruby/object:Location
attributes:
city: springfield
business_id: "2"
id: "3"
phone: 321-1234
address: 123 Main St
attributes_cache: {}

business: !ruby/object:Business
attributes:
name: A Bar
updated_at: 2009-08-31 21:13:10
website: www.abar.com
id: "2"
created_at: 2009-08-31 21:13:10
business_owner_id: "1"
attributes_cache: {}

=> nil
>>

最佳答案

尝试改变

@locations.paginate(:page => 1, :per_page => 2)

@locations = @locations.paginate(:page => 1, :per_page => 2)

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

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