开发者

Creating logs & history in Rails3

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜