I'm trying to create some logs and history about users in my app.
For example, I'd like to know how many posts any user had total, on any given day. And some other cool metrics.
Off the bat, my assumption is that the only way to do this, is to have a cron job running 开发者_如何学Gosome tasks, that calculates these numbers, and stores them for each user, every day, in a new table.
Is there a better or alternative way to go about this?
You could use a plug-in such as make_resourceful
. In the case of posts, you could override the after :create
method to post to a table that tracks the number of posts for the user. In the case of page views, you could override the after :show
method.
You must include the the make_resourceful
methd in the controller class. For example:
class BlogPostsController < ApplicationController
make_resourceful do
actions :all
response_for after :create do |format|
BlogPostAudit.create (:user => current_user)
end
end
end
精彩评论