我在這裏錯過了什麼?我正在使用haml_scaffold生成器,並且這些頁面在will_paginate下正常工作。當我開始修補時,最終會出現這個'total_pages'錯誤,我不確定我在做什麼導致它。任何人有任何見解? 我正在使用mislav-will_paginate 2.3.11。will_paginate undefined method`total_pages'
[email protected]:~/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
>>
Ghaaa!我知道這是愚蠢的。一直盯着屏幕。甜蜜的感謝! – mikewilliamson 2009-09-11 11:38:24
謝謝Jirapong!你剛剛解決了我的5小時問題! 爲他人提示:如果使用searchlogic,試圖使用search.paginate會拋出錯誤。在@whatever對象上使用.paginate方法可能會有所幫助:-) – 2009-10-03 18:08:13
我有以下查詢,它與解決方案看起來很相似,但它仍會拋出相同的錯誤:@users = @ company.users.page (params [:page])。sort_by {| u | u.cards.first.card_visits.count} .reverse'任何提示? – 2012-04-25 18:17:26