launchscout / nku

NKU Class Spring
5 stars 14 forks source link

attendances on student index? #61

Closed swiedaa1 closed 10 years ago

swiedaa1 commented 10 years ago

Is it possible to reference a variable I use for the attendance index page on the student index page? For example, I am trying to do this on the student index:

<% if @attendances.seat == 1 %> <%= @current.name %> <% end %>

But I get this error: undefined method `seat' for nil:NilClass

screenshot 2014-02-18 12 15 27

swiedaa1 commented 10 years ago

Fixed this by using the Attendances index page instead.

awh112 commented 10 years ago

How exactly did you do what you needed to do from the attendances index page? It looks like you were doing what I am trying to do, which is set the students on the student index page.

swiedaa1 commented 10 years ago

I did something similar to the above, but am using the attendances index page instead since it wasn't working on the student index page at all. I don't know if there's a way to get those variables to work from there. However, this way doesn't use the in_seat thing we're supposed to use later in the assignment so I'm not sure if this is a valid way of doing it or not.

<% @attendances.each do |a| %> <% if a.seat == 3 %> <%= User.find(a.user_id).nickname %><br /> <% end %> <% end %>

awh112 commented 10 years ago

I kind of realized that while I was working on it. As a side thought, I also thought you might get away with putting this in the application controller like we did for the current user, but like you said, I'm not sure if this is bad practice or not.

awh112 commented 10 years ago

But again, how can we use the in_seat method. When I use it, I get an active record relation, which looks basically like the generated query. Can we use that?

awh112 commented 10 years ago

Well, I opened a few new issues for some of these questions. Thanks @swiedaa1!

swiedaa1 commented 10 years ago

I...would love to help you more. I'm seriously just winging it. I look at the homework, and tackle one part at a time. I am not very good at programming/coding/scripting/this. I have a lot of difficulty with the logic bit. I tend to over complicate the tasks we are given because I dont know the best way to handle it. Honestly, I follow your issues on github and kind of use that as a guide since you tend to start working and post before I do. I never know the right questions to ask :(

awh112 commented 10 years ago

Yeah, I feel you there. If it helps, I found a nice way to kind of get at what we need, you have to call an action on the relation. For example:

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

If you call .all or some other function off of that relation object, you can get at whats inside of it.

swiedaa1 commented 10 years ago

Thanks so much! I'll have to mess around with this tomorrow.

awh112 commented 10 years ago

No problem. I just updated my new thread with this same info so you can follow that one for any more updates that might come along.