Activist
Activity stream in rails 3.0 applications
Based on http://activitystrea.ms/spec/1.0/atom-activity-01.html
Requirements
- Redis
Installation
Just run the following command :
gem install activist
Then in your Gemfile add the following line :
gem 'activist'
And run
bundle install
Usage
First generate a status model :
rails generate activist:install
This command creates a new model called ActivistStatus in 'app/models' :
class ActivistStatus < ActiveRecord::Base
serialize :data, Hash
end
It also creates a new migration for the ActivistStatus model so don't forget to migrate your database :
rake db:migrate
Then add activist in your user model :
class User < ActiveRecord::Base
include Activist::Actor
stream :public do
all
end
stream :private do
[user]
end
end
And finally create some activities :
class Post < ActiveRecord::Base
include Activist::Action
belongs_to :user
activities :public, :on => :after_create
activities :private, :actor => :user, :action => :posted, :on => :after_create
activities :public, :on => :after_update, :data => proc { |post| post.changes }
after_destroy
activity :private, :action => :deleted
end
def promote
self.title = "[PROMOTED] #{self.title}"
activity :private, :action => :promoted, :data => proc { |post| { :title => post.title } }
end
end