I'm creating a Ruby on Rails chatroom web application but ran into a problem while trying to update "last active" times for a user. Each "Client" model is linked to a "LoginStatus" model through an association. Every 5 seconds I poll the server and update the "latestNew" column for the model that is associated with the client. However, the column 1) never updates and 2) shoots me a "Cookie Overflow" error. Here is my code.
jquery ajax call to the "updateLoginStatus" url
function updateLoginStatus () {
$.ajax({
url: "updateLoginStatus",
type: "POST",
success: function (data) {
//Nothing to do on success for now
}
})
}
The controller
def updateLoginStatus
currentUser = session[:user]
newestTime = currentUser.login_status
newestTime.latestTime = Time.now
newestTime.save
render :nothing => true
end
Every time I check the console the latestNew column is still not updated. How should I fix this?
You are retrieving the session from the user which probably contains the user-id. With this user-id you should access the User model and find this particular user. After that you are able to call login_status on the object. This is the code what you'll need to use in the controller:
currentUser = User.find(session[:user])