@mem = [] @tran = Transport.find_all_by_month_and_vehicle(date,vehicle) tran.each do |t| @mem << [Student.find_by_id(t.mem_id), t.transport_date, vehicle.no] if t.mem_type=="Student" @mem << [Employee.find_by_id(t.mem_id), t.transport_date, vehicle.no] if t.mem_type=="Employee" end
And in the view page I am looping and displaying it as
@mem.each do |m| <tr> <td><%= link_to m[0].first_name} %></td> <td > <%= m[0].age %></td> <td id="date"> m[1] </td> <td id="vehicle"> m[2] </td> </tr> <%end%>
But I am getting duplicate entries in the table... So I neeed to remove duplicates and display only unique values.. I tries doing
@mem << [Student.find_by_id(t.mem_id), t.transport_date, vehicle.no].uniq! if t.mem_type=="Student".. But it is not working.. Please help
Iterate in view
@mem.each do |mem|
mem.name
mem.vehicle
Should work if you have the relations set up. You should go read one or two tutorials about relations and how to set them up.