I want to track the number of user visits to a site. A visit counter (part of User model) is incremented if prior visit was more then 30 minute ago. I am using Rails and Devise:
class ApplicationController < ActionController::Base
before_filter :authenticate_user!
before_filter :update_visits
def update_visits
current_user.increment!(:visits) if !current_user.nil? && current_user.updated_at < 30.minutes.ago
end
end
this would work great, except I have devise :rememberable turned on. So the sequence of SQL calls from :authenticate_user! is this:
SELECT "users".* FROM "users" WHERE "users"."email" = 'person_1@example.com' LIMIT 1
UPDATE "users" SET "remember_created_at" = '2012-11-21 20:13:53.011322', "updated_at" = '2012-11-21 20:13:53.012791' WHERE "users"."id" = 1
So the visits variable is never incremented because updated_at is set to the current time in the rememberable call. How do I put update_visits call after authenticate but before rememberable?
Thank you