I have done this
def show_selected_students(selected_students, students)
student = students.map{|a| a.name}
selected_students = selected_students.split(",")
@student_selected = selected_students.map {|i| student[i.to_i] }
end
in students I am fetching given data
#<ActiveRecord::Relation [#<Student id: 1, name: "XYZ",>, #<Student id: 2, name: "test1">, #<Student id: 3, name: "cherry">, #<Student id: 4, name: "mary">, #<Student id: 5, name: "hary">, #<Student id: 35, name: "hen">, #<Student id: 44, name: "duck">, #<Student id: 62, name: "try">]>
and in selected_students I am getting 2,3,4
Now I want to fetch those students whose id match with selected_students for this I had written this but it gives me this output ['cherry', 'mary', 'hary']
i.e id 3,4,5 but I want 2,3,4 Please guide me how to solve this. Thanx in advance.
You can try this:
def show_selected_students(selected_students, students)
selected_students = selected_students.split(",")
@student_selected = students.where(:id => selected_students).map{|a|a.name}
end
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments