Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to call method on query result in Rails
    text
    copied!<p>how to call method on query result in Rails i have following code in my projects controller</p> <p>def inprogress_report @projects = Project.all</p> <p>@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 estimated_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') )) limit 1) as Manager from projects p where p.status IN ('16','14','15','17','18','19','20') group by p.id")</p> <p>Now i want to make serch on @project_list result</p> <p>so i have put </p> <pre><code>@project_list = @project_list.search(params[:search]) </code></pre> <p>and in my project.rb there is </p> <pre><code>def search(search) if search where('name LIKE ?', "%#{search}%") else find(:all) end end </code></pre> <p>but gives me error undefined search method...</p> <p>Can i use Active Record::Base.connection.select_all for above query and in a result i want further sorting is that possible plz guide me</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload