GithubHelp home page GithubHelp logo

vkhang55 / public_activity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from public-activity/public_activity

1.0 2.0 1.0 214 KB

Smooth acitivity tracking for models - similiar to github's Public Activity

Home Page: https://github.com/pokonski/public_activity

License: MIT License

Ruby 100.00%

public_activity's Introduction

PublicActivity Build Status

public_activity provides smooth activity tracking for your ActiveRecord models in Rails 3. Simply put: it records what has been changed or edited and gives you the ability to present those recorded activities to users - in a similar way Github does it.

Example

A picture is worth a thousand words, so here is a visual representation of what this gem is about:

Example usage

Installation

You can install this gem as you would any other gem: gem install public_activity or in your Gemfile: gem 'public_activity'

Usage

Create migration for activities (in your Rails project):

rails g public_activity:migration
rake db:migrate

Add 'tracked' to the model you want to keep track of:

class Article < ActiveRecord::Base
  tracked
end

To default the owner to the current user (optional)

#Aplication Controller
before_filter :define_current_user

def define_current_user
  User.current_user = current_user
end

#User.rb (model)
class User < ActiveRecord::Base
  cattr_accessor :current_user
end

And now, by default create/update/destroy activities are recorded in activities table. To display them you can do a simple query:

# some_controller.rb
def index
  @activities = PublicActivity::Activity.all
end

And in your views:

<% for activity in @activities %>
  <%= activity.text %><br/>
<% end %>

The only thing left is to add templates (config/pba.yml), for example:

activity:
  article:
    create: 'Article has been created'
    update: 'Someone has edited the article'
    destroy: 'Some user removed an article!'

Place this in a file and reference it in a Rails initializer.

PublicActivity::Activity.template = YAML.load_file("#{Rails.root}/config/pba.yml")

This is only a basic example, refer to documentation for more options and customization!

Documentation

You can find documentation here

License

Copyright (c) 2012 Piotrek Okoński, released under the MIT license

public_activity's People

Contributors

farnoy avatar harrigan avatar pokonski avatar sbower avatar vkhang55 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

newecx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.