简体   繁体   中英

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 some 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM