# public_activity: activity tracking for ActiveRecord, Mongoid and MongoMapper models

> The public_activity gem records create, update and destroy events on Rails models and renders them as a feed. It is a small, opinionated layer over ActiveRecord, and its main cost is the extra activities table and the view partials you have to write.

**public-activity/public_activity** — Easy activity tracking for models - similar to Github's Public Activity

- Repository: https://github.com/public-activity/public_activity
- Stars: 2,990 · Forks: 329
- Language: Ruby
- License: MIT
- Published: 2026-09-24 · Updated: 2026-09-24 · Language: en
- Canonical page: https://hysenlabs.com/projects/public-activity-public-activity

## The problem public_activity solves for Rails models

Rails gives you timestamps and callbacks, not a history. If a user edits an article, the previous state is gone unless you wrote an audit table yourself. public_activity targets that gap: it records what has been changed or created on a model and gives you a way to present those records to users, following the GitHub activity feed model. The intended audience is a Rails developer who already has models with CRUD actions and wants a feed without designing a polymorphic events schema from scratch. The gem supports ActiveRecord, Mongoid 3 and MongoMapper as backends, so it is not tied to a SQL database, though ActiveRecord is the default and the only path with a generated migration. It is not an audit log in the compliance sense: the README describes create, update and destroy tracking plus custom activities, and says nothing about field-level diffs, retention rules or tamper evidence.

## How the tracked module records and renders activities

The mechanism has two halves. On the write side, including PublicActivity::Model and calling tracked on a model hooks into the persistence flow so that create, update and destroy actions are recorded in the activities table by default. The README states that this is all you need for basic CRUD actions. Beyond the defaults, create_activity lets you push an event manually with the parameters you choose, for example a key and an owner. On the read side, activities are ordinary rows you query through PublicActivity::Activity, and rendering is delegated to partials. The gem looks for views in app/views/public_activity, and for an activity whose key is "activity.user.changed_avatar" it looks for app/views/public_activity/user/_changed_avatar. The "activity." prefix in the key is optional and kept for backwards compatibility. When no partial exists, the gem falls back to I18n translation of the key, which means a project can ship translated strings before it ships templates. That fallback order is the design decision worth noticing: templates win, translations are the safety net, and a typo in a key silently changes which of the two you get.

## Installing public_activity and recording the first activity

Installation is the usual gem path. Add the gem to your Gemfile and run bundle, or install it directly.

```ruby
gem 'public_activity'
```

For ActiveRecord, the README gives a generator and a migration step. Run both from your Rails project root; the generator creates the activities migration and the rake task applies it.

```bash
rails g public_activity:migration
rake db:migrate
```

If you use Mongoid or MongoMapper instead, the README says to create an initializer and set the ORM there rather than running the migration.

```ruby
# config/initializers/public_activity.rb
PublicActivity::Config.set do
  orm :mongoid
end
```

Then include the module in the model you want to watch and call tracked. After this, create, update and destroy on that model are recorded without further code.

```ruby
class Article < ActiveRecord::Base
  include PublicActivity::Model
  tracked
end
```

For a non-CRUD event, call create_activity on the tracked model with the parameters you need. The README's example passes a key and an owner, which is how you attribute an action to a user.

```ruby
@article.create_activity key: 'article.commented_on', owner: current_user
```

Finally, query the Activity model in a controller and render it in a view. render_activities is an alias for render_activity, and activity.render(self) is equivalent to calling the helper on that single activity.

```erb
<%= render_activities(@activities) %>
```

## Where public_activity gets in the way

The tracked call is blunt. The README says create/update/destroy activities are recorded by default, and it does not document a way to exclude a specific attribute, suppress a particular update, or cap how many rows a busy model writes. A model that is updated on every request will produce an activity per update, and the gem's answer to that is not to use tracked: include only the lightweight Common module and call create_activity yourself when the event is meaningful. That is a real fork in the design, and it is worth deciding before you add the migration, because switching later means revisiting every model. The second cost is rendering. Activities without partials fall back to I18n strings, which is fine for a plain sentence but not for an avatar, a timestamp and a link. Layouts and locals exist for that, and the README notes that activity layouts are themselves partials, so they carry the underscore prefix, and that locals are preferred over passing variables directly in the options hash because it avoids shadowing activity parameters from the database. Version support is the third boundary: version 3.x requires Ruby 3.0+ and Rails 6.1+, and the README states that issues for older Ruby and Rails are closed without resolution and pull requests are not accepted. If you are on Ruby 2.7 or Rails 5.x, the README points to version 2.x until you upgrade.

## public_activity versus hand-rolled callbacks and audit gems

The obvious alternative is a before_save or after_commit callback that writes to your own events table. That gives you exact control over what counts as an event and lets you store a diff of changed attributes, which public_activity does not describe. What you give up is the rendering layer: the partial lookup under app/views/public_activity, the I18n fallback, layouts and locals, and the polymorphic Activity model that already knows how to point back at the tracked record. The other alternative is an audit-oriented gem that captures attribute-level changes for every write. public_activity is not that. It is a feed: the README's framing is GitHub-style activity presentation, and the custom activity example is a domain event (article.commented_on) rather than a field change. If your requirement is "show users what happened recently," the gem covers it. If your requirement is "prove what the record looked like at 14:03 last Tuesday," the README offers nothing on that front and you should look elsewhere.

## Maintenance, releases and licence

The repository is not archived, and the last push was on 2026-06-08. The most recent release listed is v3.0.2 from 2026-01-13, after v3.0.0 in January 2024 and v2.0.2 in July 2022. That cadence matters for upgrade planning: the 3.x line is where Ruby 3.0+ and Rails 6.1+ live, and the 2.x line is the documented escape hatch for older runtimes, so a Rails upgrade and a gem upgrade are coupled. The repository carries an Appraisals file and a gemfiles directory, which is the standard Rails gem pattern for testing against several dependency versions, so a bump in Rails support is something you can check against those files rather than guessing. On licensing, the repository ships MIT-LICENSE and the project is listed as MIT. That is permissive and imposes no obligation to publish your own application code, but it is a copyright licence, not a support contract: nothing in it commits the maintainers to fix an issue on a version they have declared unsupported. Read the licence text before relying on that summary.

## Conclusion

Adopt public_activity if you have Rails 6.1+ with Ruby 3.0+ and you want a model-level activity feed without building the persistence and rendering layer yourself. Do not adopt it if you are pinned to Ruby 2.7 or older or Rails 5.x, since the README states those versions are unsupported and related issues are closed without resolution. Before wiring it in, decide whether you want the full tracked module or only PublicActivity::Common, and confirm that your application already has somewhere to render the partials under app/views/public_activity.

## FAQ

### What is public_activity?

It is a Ruby gem that provides activity tracking for ActiveRecord, Mongoid 3 and MongoMapper models in Rails 6.1+, recording what has been changed or created and letting you present those records to users in a feed similar to GitHub's.

### Can you give me some examples of activities in public_activity?

The README's example is a custom event triggered with create_activity using key: 'article.commented_on' and owner: current_user. By default, create, update and destroy actions on a tracked model are recorded as activities without any extra code.

### How do I install the public_activity gem?

Install it as any other gem, then for ActiveRecord run rails g public_activity:migration followed by rake db:migrate in your Rails project. For Mongoid or MongoMapper, the README instead has you create config/initializers/public_activity.rb and set orm :mongoid or orm :mongo_mapper.

### Which Ruby and Rails versions does public_activity 3.x support?

Version ~> 3.0 supports Ruby 3.0+ and Rails 6.1+. For Ruby 2.7 and below with Rails 5.0+, the README points to version ~> 2.0 until you can upgrade.

### Where does public_activity look for activity view templates?

It looks in app/views/public_activity. An activity with key "activity.user.changed_avatar" maps to app/views/public_activity/user/_changed_avatar, and the "activity." prefix is optional.

## Sources

- [Issues](https://github.com/public-activity/public_activity/issues)
- [License: MIT](https://github.com/public-activity/public_activity/blob/main/LICENSE)
- [public-activity/public_activity on GitHub](https://github.com/public-activity/public_activity)
- [README](https://github.com/public-activity/public_activity/blob/main/README.md)
- [Releases](https://github.com/public-activity/public_activity/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/public-activity-public-activity
