【发布时间】:2013-03-21 19:25:35
【问题描述】:
我有一个搜索模型,它构造一个基本上是原始 SQL 的字符串。此字符串通过 find_by_sql 调用运行,并在下面的第 5 行返回给控制器(@search.query
1 def roster_builder
2 authorize! :access_roster_builder, current_coach
3 @search = Search.new(sport: current_coach.primary_sport, conditions: params[:search])
4
5 @athletes = @search.query.page(params[:page]).per_page(8)
6
7 if params[:refresh]
8 render "athletes_refresh"
9 else
10 render "athletes" if request.format.js?
11 end
12 end
这会返回一个数组,但我得到了这个错误:
NoMethodError (undefined method `page' for #<Array:0x00000105b7add0>)
所以我发现在哪里插入以下内容可以解决这个问题:
require 'will_paginate/array'
我已经尝试将它放在我的控制器中,但 will_paginate.rb 初始化文件无济于事。我什至对 find_by_sql 结果做了 .to_a ——同样的错误。这里到底有什么问题??我正在使用 will_paginate 版本 3.0.4,所以它是完全最新的。在 github 上,它甚至说 require 应该可以正常工作:https://github.com/mislav/will_paginate/wiki/Backwards-incompatibility
【问题讨论】:
标签: sql ruby-on-rails ruby postgresql will-paginate