简体   繁体   English

rails searchlogic和will_paginate#的未定义方法`order&#39; <WillPaginate::Collection:0x37530ac>

[英]rails searchlogic and will_paginate undefined method `order' for #<WillPaginate::Collection:0x37530ac>

Does anyone have the same problem or a working solution? 有谁有同样的问题或可行的解决方案? I get always this error message, here are model, controller and view code 我总是收到此错误消息,这是模型,控制器和视图代码

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" %>

please help, thanks in advance 请帮助,在此先感谢

You are getting this error because the first parameter that should be passed to the will_paginate view helper method is the collection you want to paginate: 之所以出现此错误,是因为应该传递给will_paginate视图帮助器方法的第一个参数是您要分页的集合:

<%= will_paginate @profiles %>

—whereas searchlogic's order helper method returns a link, not a collection. —而searchlogic的order帮助器方法将返回一个链接,而不是一个集合。 You probably want to do this: 您可能想这样做:

<%= order @profiles, :by => :created_at, :as => 'name' %>
<%= will_paginate @profiles %>

I'm not sure if it will work as intended, I haven't tried it. 我不确定它是否会按预期工作,但我还没有尝试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM