Sorry if this has come up before - I promise I've tried to find it.
My rails app compares a user's football score predictions against actual football scores. If the result is right (eg Barcelona win), you get 1 point. If the result AND score are right (Barcelona win 3-0), you get three points.
The 'if' logic etc is all fine, but I'm struggling to access the 'points' record in my user model. Below is what I have in the controller - any idea what should go in the lines where I'm assigning points to the user (highlighted below)?
This is just an excerpt and the index is there for something separate, so please don't be sidelined too much by that - I'm just trying to work out what replaces the two highlighted lines. All advice welcome!
Predictions controller
def update scores
Prediction.joins(:user).each_with_index do |p, :|
if p.predictionarray[0] == Leagueresult.last.resultarray[0] && p.predictionarray[1..2] == Leagueresult.last.resultarray[1..2]
User.points = User.points + 3 <<<<< What goes on this line?
elsif p.predictionarray[0] == Leagueresult.last.resultarray[0] && p.predictionarray[1..2] != Leagueresult.last.resultarray[1..2]
User.points = User.points + 1 <<<<< And this line?
end
end
You are trying to reference the User
-model, instead of a User
-classed object. It seems that the user-object you are looking for would be p.user
.