ruby on rails - Displaying and sorting multiple queries together -


i display data combines information multiple queries. example:

@projects = @company.projects @assignments = @company.assignments @tasks = @company.tasks 

how can take these 3 queries , display big table shows projects, assignments, , tasks, sorted created_at? desired result this:

7/11  task created company xc project xp. 7/10  project xp created user u. 7/09  task created company yc project yp. 7/09  assignment created company yc project yp. 7/08  project yp created user u. 

you can use sql union query if want more complex stuff getting newest x entries or pagination.

if know data few, can collect results in array , sort created_at

@events = @projects.to_a + @assignments.to_a + @tasks.to_a @events.sort_by! { |e| e.created_at } 

Comments