Rails searchlogic 和 will_paginate 未定义方法“order”对于 #

发布于 2024-09-08 15:54:02 字数 390 浏览 2 评论 0原文

有人有同样的问题或有效的解决方案吗? 我总是收到此错误消息,这里是模型、控制器和视图代码,

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

请帮忙,提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与风相奔跑 2024-09-15 15:54:02

您收到此错误是因为应传递给 will_paginate 视图辅助方法的第一个参数是您要分页的集合:

<%= will_paginate @profiles %>

— 而 searchlogic 的 order 辅助方法返回一个链接,不是一个集合。您可能想这样做:

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

我不确定它是否会按预期工作,我还没有尝试过。

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 @profiles %>

—whereas searchlogic's order helper method returns a link, not a collection. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文