Reputation: 99254
I want to add a panel that shows site access stats to a Rails 3 application (as in Google Analytics). A naïve method to do this is to record IP addresses into a designated table with their access times.
Is there a function or a callback that is called at each request? If not, is there any other way I can count the total number of accesses to a Rails 3 application?
Upvotes: 1
Views: 1221
Reputation: 153
I know it's old but when someone would like to know:
(total times) = Request.count
Upvotes: 0
Reputation: 239240
The "callback" you're looking for is a simple before_filter
applied inside your application controller.
class ApplicationController < ActionController::Base
before_filter :log_request
protected
def log_request
# Write request information to the database or log file
end
end
You are correct in calling this a very naive approach though. You could also simply analyze your log files to obtain the same information.
Upvotes: 4