百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

activity_streams

> 编程语言
开源

ActivityStreams 是一个 Rails 插件,提供了一个可自定义的框架,用于目录化和发布用户活动和社交对象。

171 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

ActivityStreams 是一个 Rails 插件,提供了一个可自定义的框架,用于目录化和发布用户活动和社交对象。

ActivityStreams

ActivityStreams is a Rails Plug-in providing a customizable framework for cataloging and publishing user activity and social objects.

Developed and tested on Rails 2.1 Tested on Rails 2.3.10

Example

  1. Generate initialization class, migration, controllers, and tests:

    ./script/generate activity_streams User

The only option is the name of the model that holds your User.

  1. Add the Routes, in routes.rb

    map.activity_streams

  2. Run the migration

    rake db:migrate
    
  3. 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").

  1. Edit application controller and include the activity logger:

    class ApplicationController 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  :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.
  1. Display a stream in one of your views. For example, from ./app/views/users/show.html.erb:

Recent Activity

  1. Define the required methods. The plug-in needs to know the current logged in user and if that user is an admin. So the following methods must be defined.

a) The User model needs an "admin?" method

b) The controller need a "current_user" controller and helper method

c) The controller needs "logged_in?" controller and helper method

d) Finally, either the generated controllers need to be modified or a login_required and admin_required methods must be written for the controllers.

Except for the admin methods above, restful_authentication defines all these methods for us. http://agilewebdevelopment.com/plugins/restful_authentication

  1. Activities should now be logging. You should be able to generate and view activities now. A good interactive test is to play with the preferences and atom feed found here:

    http://localhost:3000/activity_stream_preferences

  2. Fix the generated tests and add new ones. Activity streams generator generates unit, controller, and integration tests. These tests will need to be fixed as your fixtures will be different than the ones provided.

Finally, you should write some tests for your controllers where you add your activities. For example: class FeedsControllerTest 1, :creators => ['1'], :feed_digest_option => 'daily' end end

  def test_follow_category_generates_activity
    login_as :fred
      assert_difference('ActivityStream.count', +1) do
      post :set_my_feeds, :id => 1, :categories => ['1'], :feed_digest_option => 'daily'
    end
  end

  def test_follow_three_generates_three_activities
    login_as :fred
      assert_difference('ActivityStream.count', +3) do
      post :set_my_feeds, :id => 1, :categories => ['1'], :creators => ['2','3'], :feed_digest_option => 'daily'
    end
  end

  def test_follow_creator_activity_has_correct_data
    login_as :fred

    post :set_my_feeds, :id => 1, :creators => ['1'], :feed_digest_option => 'daily'
    activity = ActivityStream.find(:last)

    assert_equal(activity.object_id, 1)
    assert_equal(activity.object_type, 'Creator')
    assert_equal(activity.actor_id, users(:fred).id)
    assert_equal(activity.actor_type, 'User')
    assert_equal(activity.verb, 'now_follows')
  end

You should be able to modify the views by copying the view directorys from the plugin into your app/views directory.

Copyright (c) 2008 Matson Systems, Inc. Released under the BSD license found in the file LICENSE

Issues· 3 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言