我有一群学生(学生)。我需要从中删除重复记录并仅获取唯一的学生详细信息。在我的控制台中,我越来越喜欢
students = [
[#<Student id: 2, admission_no: "2", gender: "m", blood_group: "A">, Wed, 11 Sep 2013, "Student"],
[#<Student id: 17, admission_no: "17",gender: "m", blood_group: "AB">, Sat, 14 Sep 2013, "Student"],
[#<Student id: 17, admission_no: "17",gender: "m", blood_group: "AB">, Tue, 17 Sep 2013, "Student"],
[#<Student id: 2, admission_no: "2",gender: "m">, Tue, 17 Sep 2013, "Student"],
[#<Student id: 17, admission_no: "17",gender: "m", blood_group: "AB">, Thu, 12 Sep 2013, "Student"]
]
我尝试使用students = students.uniq
. 但它正在获得零值..因为我还插入了另外两个属性(日期和类型,即最后两个..)从另一个表中检索到。但我需要显示唯一的学生记录及其类型..我该怎么做做吗?请帮忙。我正在尝试循环这样的数组..
@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
在视图页面中,我正在循环它并像这样显示它
@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%>