Rail3ActivityStreams ==================== Rails3ActivityStreams is a Rails 3 gem providing a customizable models for cataloging and publishing user activity base upon rails3-activity-streams (https://github.com/face/activity_streams) Developed and tested on Rails 3.0.3 Example ======= 1) Generate initialization class, migration, controllers, and tests: rails generate activity_streams User The only option is the name of the model that holds your User. 2) Add the Routes, in routes.rb resources :activity_stream_preferences resources :activity_streams 3) Run the migration rake db:migrate 4) Edit ./config/initializers/activity_streams.rb. Here you must define your on list of ACTIVITY_STREAM_ACTIVITIES. ACTIVITY_STREAM_ACTIVITIES are a hash of activities used on the entire site. ACTIVITY_STREAM_ACTIVITIES are a grouping of activities so verbs like "now follows" and "no longer follows" can be tracked as the same activity. Please ensure the keys are unique. ACTIVITY_STREAM_LOCATIONS relies on a application controller method "activity_stream_location". If you change or add to ACTIVITY_STREAM_LOCATIONS you will probably need to override the activity_stream_location method. The ACTIVITY_STREAM_USER_MODEL, _CLASS, and _MODEL_ID should not need changing. However, set ACTIVITY_STREAM_USER_MODEL_NAME to be the method of your user model the returns a friendly name (like "firstname lastname"). 5) Edit application controller and include the activity logger: class ApplicationController < ActionController::Base include LogActivityStreams #... 6) Add logging calls to each controller for all the actions you want to log activities. For example: class FeedsController < ApplicationController #... log_activity_streams :current_user, :friendly_name, :now_follows, :@new_creators, :title, :set_my_feeds, :follow_creator, {:total => 1 } log_activity_streams :current_user, :friendly_name, :now_follows, :@new_categories, :name, :set_my_feeds, :follow_category, {:total => 1 } log_activity_streams :current_user, :friendly_name, :no_longer_follows, :@destroyed_creators, :title, :set_my_feeds, :follow_creator, {:total => -1 } log_activity_streams :current_user, :friendly_name, :no_longer_follows, :@destroyed_categories, :name, :set_my_feeds, :follow_category, {:total => -1 } #... end And an example with an indirect object: class Posts < ApplicationController log_activity_streams :current_user, :friendly_name, :posted, :@post, :activity_title, :create, :posted_message, {:indirect_object => :forum_owner, :indirect_object_name_method => :title, :indirect_object_phrase => 'about indirect_object' } #... end The arguments for log activity stream are actor: a method or instance variable the is a single model or Array of models. An Array will generate multiple activities actor_method_name: A method name that returns a display-able name for the actor model verb: The verb for the activity. object: a method or instance variable the is a single model or Array of models. An Array will generate multiple activities object_method_name: A method name that returns a display-able name for the object model action: The name of the action that triggers this activity. activity: The activity grouping, the key should be predefined in ACTIVITY_STREAM_ACTIVITIES. options: A hash of options. Currently the options can take: :status for non display-able, debug, or internal activities :total for keeping total counts across grouped activities in the activity_stream_totals table. The :total can be either a Fixnum (positive or negative)or the symbol name of an instance variable or method. Copyright (c) 2010 CoffeeBanana Released under the BSD license found in the file LICENSE based on wonderful piece of work from: Matson Systems, Inc.