是否可以将 will_paginate 与 find_by_sql 结合起来?
在我的 Rails 应用程序中,我想使用 will_paginate
gem 对我的 SQL 查询进行分页。这可能吗?我尝试做这样的事情,但没有成功:
@users = User.find_by_sql("
SELECT u.id, u.first_name, u.last_name,
CASE
WHEN r.user_accepted =1 AND (r.friend_accepted =0 || r.friend_accepted IS NULL)
.........").paginate(
:page => @page, :per_page => @per_page,
:conditions => conditions_hash,
:order => 'first_name ASC')
如果没有,你能推荐一种解决方法吗?我不想编写自己的分页。
In my Rails application I want to use the will_paginate
gem to paginate on my SQL query. Is that possible? I tried doing something like this but it didn't work:
@users = User.find_by_sql("
SELECT u.id, u.first_name, u.last_name,
CASE
WHEN r.user_accepted =1 AND (r.friend_accepted =0 || r.friend_accepted IS NULL)
.........").paginate(
:page => @page, :per_page => @per_page,
:conditions => conditions_hash,
:order => 'first_name ASC')
If not, can you recommend a way around this? I don't want to have to write my own pagination.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
您使用的 will_paginate 和 Rails 版本是什么?
Try this:
What will_paginate and rails version are you using?
使用
paginate_by_sql
,即作为一般规则,任何查找器都可以通过将
find*
替换为paginate*
来进行分页。Use
paginate_by_sql
, i.e.As a general rule any finder can be paginated by replacing the
find*
withpaginate*
.