[英]rails searchlogic and will_paginate undefined method `order' for #<WillPaginate::Collection:0x37530ac>
有誰有同樣的問題或可行的解決方案? 我總是收到此錯誤消息,這是模型,控制器和視圖代碼
class Profile < ActiveRecord::Base
cattr_reader :per_page
@@per_page = 10
end
def index
@search = Profile.search(params[:search])
@profiles = @search.paginate(:page => params[:page])
end
<%= will_paginate order @profiles , :by => :created_at, :as => "name" %>
請幫助,在此先感謝
之所以出現此錯誤,是因為應該傳遞給will_paginate
視圖幫助器方法的第一個參數是您要分頁的集合:
<%= will_paginate @profiles %>
—而searchlogic的order
幫助器方法將返回一個鏈接,而不是一個集合。 您可能想這樣做:
<%= order @profiles, :by => :created_at, :as => 'name' %>
<%= will_paginate @profiles %>
我不確定它是否會按預期工作,但我還沒有嘗試過。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.