【发布时间】:2013-12-10 15:06:55
【问题描述】:
我想要一个数据搜索功能。搜索后,按列排序,然后将结果限制为 200。最后用 will_paginate 分页。
我的控制器
def search
title = params[:title]
company = params[:company]
location_id = params[:location_id]
page = params[:page]
@wages = Wage.search(title, company, location_id,page)
end
我的模型
def self.search(title, company, location_id, page) 如果 location_id.present?
paginate :conditions => ['title LIKE ? AND company LIKE ? AND location_id = ?', "%#{title}%", "%#{company}%", location_id],
:order => "total DESC",
:page => page,
:per_page => 20
else
paginate :conditions => ['title LIKE ? AND company LIKE ?', "%#{title}%", "%#{company}%"],
:order => "total DESC",
:page => page,
:per_page => 20
end
结束
我尝试更改为以下代码以限制结果:
paginate :conditions => ['title LIKE ? AND company LIKE ?', "%#{title}%", "%#{company}%"].limit(200)
但它不起作用。最好的方法是什么?
【问题讨论】:
标签: ruby-on-rails ruby pagination