MuckActivities¶ ↑
Installation¶ ↑
The muck activities engine is part of the muck framework and relies upon the muck-engine. Install with
sudo gem install muck-activites
This should also install the dependencies.
Usage¶ ↑
This engine implements simple activity tracking.
Models that can have activity feed should call ‘include MuckActivities::Models::MuckActivityConsumer’
Example: class User include MuckActivities::Models::MuckActivityConsumer end
Adding an item to the activity feed with ‘include MuckActivities::Models::MuckActivitySource’ which then profiles the method ‘add_activity’
add_activity(feed_to, actor, item, template, check_method) feed_to - contains an array of objects (typically users) that have use acts_as_activity_user actor - the user performing the action item - a reference to the object that template - the template (partial) to use to render the activity check_method - and optional method to call on each object in the feed_to array that determines whether or not to add the activity Example: add_activity(user.feed_to, user, comment, 'comment')
Create an activity model that ‘include MuckActivities::Models::MuckActivity’:
class Activity < ActiveRecord::Base include MuckActivities::Models::MuckActivity end
CSS¶ ↑
Running rake muck:activities:sync will copy a default css file called muck-activities.css into your stylesheets directory.
You can include that file in your layout or copy it and modify it to meet your needs. (Don’t change the file as each time you run rake muck:activities:sync it will overwrite any changes you might have made.)
Authorization¶ ↑
Adding ‘include MuckActivities::Models::MuckActivityConsumer’ to your model will add a simple ‘can_view?’ method:
def can_view?(check_object) self == check_object end
This method determines whether or not the check_object has access to the current object’s activity feeds. For example, if the intent is to recover the activities for a given user where the user is ‘@parent’ thus:
@parent.can_view?(current_user)
The can view method will determine whether or not the current_user has the right to view the activity feed.
In most instances you will need to override this method to implement proper security. For example, for a group that has an activity feed you might add a can_view? method like this:
def can_view?(check_object) self.member?(check_object) || (check_object.is_a?(User) && check_object.admin?) end
Configuration¶ ↑
Add the following to an initializer:
MuckActivities.configure do |config|
config.enable_activity_comments = true # Enable if you would like to enable comments for your project's activities feeds config.enable_live_activity_updates = true # Turns on polling inside the user's activity feed so they constantly get updates from the site config.live_activity_update_interval = 60 # Time between updates to live activity feed in seconds # Note that this will poll the server every 60 seconds and so will increase server load and bandwidth usage. config.enable_activity_shares = true # Turn on shares in the activity feed # You can also use the 'contribute' helper method to render a richer status update if you have uploader installed and configured: config.enable_activity_file_uploads = true # Turn on file uploads in the activity feed. Requires that uploader be installed. config.enable_activity_image_uploads = true # Turn on image uploads in the activity feed. Requires that uploader and muck_albums be installed. config.enable_activity_video_sharing = true # Turn on video sharing in the activity feed.
end
Development¶ ↑
If you want to add a new activity you only need to add a template to views/activity_templates then setup the related localization. For example, to create a template for ‘comments’ add a partial called _comments.html.erb to views/activity_templates. There is a generic template available that can be used to speed development or be used as an example:
<%= render :partial => 'activity_templates/generic', :locals => { :activity => activity, :activity_css_class => 'activity-status-update' } %>
Next create an entry in en.yml
en: muck: activity_templates: comment: "Comments"
The name of the entry needs to match the name of the template. Then to add an activity you only need to do:
add_activity(user.feed_to, user, comment, 'comment')
Copyright © 2009-2010 Tatemae.com, released under the MIT license