如何在 Rails 中调用查询结果的方法我的项目控制器中有以下代码
def inprogress_report @projects = Project.all
@project_list = Project.find_by_sql("select p.id, p.name, (select sum(i.estimated_hours) from issues i where i.project_id = p.id) as estimate_hours,(select sum(t.hours) from time_entries t where p.id = t.project_id ) as Spent_Hours,(select u.firstname from users u where u.id IN(select user_id from members m where m.project_id = p.id and m.id IN (select member_id from member_roles where role_id IN (select id from roles r where r.name = 'Project Coordinator'))) limit 1) as Coordinator,(select u.firstname from users u where u.id IN(select user_id from members m where m.project_id = p.id and m.id IN (select member_id from member_roles where role_id IN (select id from roles r where r.name = 'Project Manager'))) 限制 1) 作为项目 p where p.status IN (' 16','14','15','17','18','19','20') 按 p.id 分组")
现在我想在@project_list 结果上进行搜索
所以我放了
@project_list = @project_list.search(params[:search])
在我的 project.rb 中有
def search(search)
if search
where('name LIKE ?', "%#{search}%")
else
find(:all)
end
end
但给了我错误未定义的搜索方法......
我可以使用 Active Record::Base.connection.select_all 进行上述查询吗?结果我想进一步排序是否可能请指导我