For reasons I can’t explain two odd things are happening. Firstly,
the User.update line is never executed (at least no update on User
shows in the log). Secondly after adding the @user code to increment
post count it increments by 3 with each post. I did some playing
around and if I add @user.num_posts -= 2 after @user.num_posts =
session[:user].num_posts + 1 it will increment by two. Yeah, after a
net change of -1 in the value the total becomes 2 larger than it was.
I must be missing something really, really obvious but I can’t see it.
Well, is there a reason for updating user twice? Aren’t session[:user]
and @user supposed to represent the same object? If you’re doing what
I think you are, shouldn’t you set @user =
Users.find(session[:user].id), then operate only on @user- I wouldn’t
store a user object in the session like that, and do work on it.