launchscout / nku

NKU Class Spring
5 stars 14 forks source link

Working with in_seat and absent #64

Closed awh112 closed 10 years ago

awh112 commented 10 years ago

How exactly should we work with these two functions? They seem to return an ActiveRecord relation object, but that doesn't look like what we need to work with. The only other option I thought of was using the application controller to store variables from the attendances controller, but that does not use either of these methods. What is the right way to approach this problem?

awh112 commented 10 years ago

So, I sort of found a nice way to kind of get at what we need, you have to call an action on the relation. This is what I did:

<% @seatOne = Student.in_seat(1, Date.today) %>
<% @seatOne.each do |student1| %>
  <tr>
    <td class="seats"><%= student1.nickname %></td>
...

However, I feel like to loop through this I'd need to nest those loops, which Rails doesn't seem to like. Logically I want to do this:

<% @seatOne = Student.in_seat(1, Date.today) %>
<% @seatOne = Student.in_seat(2, Date.today) %>
<% @seatOne.each do |student1| %>
<% @seatTwo.each do |student2| %>
  <tr>
    <td class="seats"><%= student1.nickname %></td>
    <td class="seats"><%= student2.nickname %></td>
...

What should I be doing instead of that?

rockwood commented 10 years ago

You'll probably want 4 separate loops like this:

<% Student.in_seat(1, Date.today).each do |student| %>
  ...
<% end %>

<% Student.in_seat(2, Date.today).each do |student| %>
  ...
<% end %>

etc...
awh112 commented 10 years ago

You are exactly right, that is what I ended up doing.