[英]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.