I have another question involving each loops. I have a view which displays a current classroom. It shows how many students are online atm, etc. Within a div located on the bottom right i have a table that lists all the available classrooms. The "name" of the classroom is a button which makes the page refresh with new parameters (:class_id) and then shows the "clicked" classroom.
My problem is identifying the proper ID for each row in the table within the each do loop.
I have this code in my view (Example)
<% @classrooms.each do |room| %>
<table>
<tr>
<td><%= room.id %></td>
<td><button onclick= "class()"><%= room.class %></button></td>
</tr>
</table>
<script>function class(){window.location = '<%= classroom_path(:class_id = room.id)%>'};</script>
<% end %>
Its redirecting with the new param, but the class_id is the same for all the entries (last one). Any help? This is probably fairly simple, not sure.