[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7889":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":16,"starSnapshotCount":16,"syncStatus":34,"lastSyncTime":35,"discoverSource":36},7889,"public_activity","public-activity\u002Fpublic_activity","public-activity","Easy activity tracking for models - similar to Github's Public Activity","",null,"Ruby",2993,331,53,17,0,4,59.96,"MIT License",false,"main",true,[24,25,26,27,28,29,30],"activerecord","activity-stream","hackertoberfest","news-feed","rails","ruby","tracking","2026-06-12 04:00:36","# PublicActivity [![Code Climate](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fchaps-io\u002Fpublic_activity.svg)](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fchaps-io\u002Fpublic_activity) [![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Fpublic_activity.svg)](http:\u002F\u002Fbadge.fury.io\u002Frb\u002Fpublic_activity)\n\n`public_activity` provides easy activity tracking for your **ActiveRecord**, **Mongoid 3** and **MongoMapper** models\nin Rails 6.1+. Simply put: it records what has been changed or created and gives you the ability to present those\nrecorded activities to users - similarly to how GitHub does it.\n\n## Table of contents\n\n- [Ruby\u002FRails version support](#ruby-rails-version-support)\n- [Table of contents](#table-of-contents)\n- [Example](#example)\n  - [Online demo](#online-demo)\n- [Screencast](#screencast)\n- [Setup](#setup)\n  - [Gem installation](#gem-installation)\n  - [Database setup](#database-setup)\n  - [Model configuration](#model-configuration)\n    - [Custom activities](#custom-activities)\n  - [Displaying activities](#displaying-activities)\n    - [Layouts](#layouts)\n    - [Locals](#locals)\n    - [Activity views](#activity-views)\n    - [I18n](#I18n)\n- [Testing](#testing)\n- [Documentation](#documentation)\n- [Common examples](#common-examples)\n- [Help](#help)\n- [License](#license)\n\n## Ruby\u002FRails version support\n\nVersion `~> 3.0`` supports Ruby 3.0+ and Rails 6.1+. For older Ruby versions\n(≤2.7) and Rails 5.0+ you can use version `~> 2.0` until you can upgrade to\nnewer versions of Ruby + Rails.\n\nIssues related to those unsupported versions of Ruby\u002FRails will be closed\nwithout resolution and PRs will not be accepted.\n\n## Example\n\nHere is a simple example showing what this gem is about:\n\n![Example usage](http:\u002F\u002Fi.imgur.com\u002Fq0TVx.png)\n\n### Demo app\n\nThe source code of the demo is hosted here: https:\u002F\u002Fgithub.com\u002Fpokonski\u002Factivity_blog\n\n## Screencast\n\nRyan Bates made a [great screencast](http:\u002F\u002Frailscasts.com\u002Fepisodes\u002F406-public-activity) describing how to integrate Public Activity in your Rails Application.\n\n## Setup\n\n### Gem installation\n\nYou can install `public_activity` as you would any other gem:\n\n    gem install public_activity\n\nor in your Gemfile:\n\n```ruby\ngem 'public_activity'\n```\n\n### Database setup\n\nBy default _public_activity_ uses Active Record. If you want to use Mongoid or MongoMapper as your backend, create\nan initializer file in your Rails application with the corresponding code inside:\n\nFor _Mongoid:_\n\n```ruby\n# config\u002Finitializers\u002Fpublic_activity.rb\nPublicActivity::Config.set do\n  orm :mongoid\nend\n```\n\nFor _MongoMapper:_\n\n```ruby\n# config\u002Finitializers\u002Fpublic_activity.rb\nPublicActivity::Config.set do\n  orm :mongo_mapper\nend\n```\n\n**(ActiveRecord only)** Create migration for activities and migrate the database (in your Rails project):\n\n    rails g public_activity:migration\n    rake db:migrate\n\n### Model configuration\n\nInclude `PublicActivity::Model` and add `tracked` to the model you want to keep track of:\n\nFor _ActiveRecord:_\n\n```ruby\nclass Article \u003C ActiveRecord::Base\n  include PublicActivity::Model\n  tracked\nend\n```\n\nFor _Mongoid:_\n\n```ruby\nclass Article\n  include Mongoid::Document\n  include PublicActivity::Model\n  tracked\nend\n```\n\nFor _MongoMapper:_\n\n```ruby\nclass Article\n  include MongoMapper::Document\n  include PublicActivity::Model\n  tracked\nend\n```\n\nAnd now, by default create\u002Fupdate\u002Fdestroy activities are recorded in activities table.\nThis is all you need to start recording activities for basic CRUD actions.\n\n_Optional_: If you don't need `#tracked` but still want the comfort of `#create_activity`,\nyou can include only the lightweight `Common` module instead of `Model`.\n\n#### Custom activities\n\nYou can trigger custom activities by setting all your required parameters and triggering `create_activity`\non the tracked model, like this:\n\n```ruby\n@article.create_activity key: 'article.commented_on', owner: current_user\n```\n\nSee this entry http:\u002F\u002Frubydoc.info\u002Fgems\u002Fpublic_activity\u002FPublicActivity\u002FCommon:create_activity for more details.\n\n### Displaying activities\n\nTo display them you simply query the `PublicActivity::Activity` model:\n\n```ruby\n# notifications_controller.rb\ndef index\n  @activities = PublicActivity::Activity.all\nend\n```\n\nAnd in your views:\n\n```erb\n\u003C%= render_activities(@activities) %>\n```\n\n*Note*: `render_activity` is a helper for use in view templates. `render_activity(activity)` can be written as `activity.render(self)` and it will have the same meaning.\n\n*Note*: `render_activities` is an alias for `render_activity` and does the same.\n\n#### Layouts\n\nYou can also pass options to both `activity#render` and `#render_activity` methods, which are passed deeper\nto the internally used `render_partial` method.\nA useful example would be to render activities wrapped in layout, which shares common elements of an activity,\nlike a timestamp, owner's avatar etc:\n\n```erb\n\u003C%= render_activities(@activities, layout: :activity) %>\n```\n\nThe activity will be wrapped with the `app\u002Fviews\u002Flayouts\u002F_activity.erb` layout, in the above example.\n\n**Important**: please note that layouts for activities are also partials. Hence the `_` prefix.\n\n#### Locals\n\nSometimes, it's desirable to pass additional local variables to partials. It can be done this way:\n\n```erb\n\u003C%= render_activity(@activity, locals: {friends: current_user.friends}) %>\n```\n\n*Note*: Before 1.4.0, one could pass variables directly to the options hash for `#render_activity` and access it from activity parameters. This functionality is retained in 1.4.0 and later, but the `:locals` method is **preferred**, since it prevents bugs from shadowing variables from activity parameters in the database.\n\n#### Activity views\n\n`public_activity` looks for views in `app\u002Fviews\u002Fpublic_activity`.\n\nFor example, if you have an activity with `:key` set to `\"activity.user.changed_avatar\"`, the gem will look for a partial in `app\u002Fviews\u002Fpublic_activity\u002Fuser\u002F_changed_avatar.(erb|haml|slim|something_else)`.\n\n*Hint*: the `\"activity.\"` prefix in `:key` is completely optional and kept for backwards compatibility, you can skip it in new projects.\n\nIf a view file does not exist, then p_a falls back to the old behaviour and tries to translate the activity `:key` using `I18n#translate` method (see the section below).\n\n#### I18n\n\nTranslations are used by the `#text` method, to which you can pass additional options in form of a hash. `#render` method uses translations when view templates have not been provided. You can render pure i18n strings by passing `{display: :i18n}` to `#render_activity` or `#render`.\n\nTranslations should be put in your locale `.yml` files. To render pure strings from I18n Example structure:\n\n```yaml\nactivity:\n  article:\n    create: 'Article has been created'\n    update: 'Someone has edited the article'\n    destroy: 'Some user removed an article!'\n```\n\nThis structure is valid for activities with keys `\"activity.article.create\"` or `\"article.create\"`. As mentioned before, `\"activity.\"` part of the key is optional.\n\n## Testing\n\nFor RSpec you can first disable `public_activity` and add the `test_helper` in `rails_helper.rb` with:\n\n```ruby\n#rails_helper.rb\nrequire 'public_activity\u002Ftesting'\n\nPublicActivity.enabled = false\n```\n\nIn your specs you can then blockwise decide whether to turn `public_activity` on\nor off.\n\n```ruby\n# file_spec.rb\nPublicActivity.with_tracking do\n  # your test code goes here\nend\n\nPublicActivity.without_tracking do\n  # your test code goes here\nend\n```\n\n## Documentation\n\nFor more documentation go [here](http:\u002F\u002Frubydoc.info\u002Fgems\u002Fpublic_activity\u002Findex)\n\n## Common examples\n\n* [[How to] Set the Activity's owner to current_user by default](https:\u002F\u002Fgithub.com\u002Fpokonski\u002Fpublic_activity\u002Fwiki\u002F%5BHow-to%5D-Set-the-Activity's-owner-to-current_user-by-default)\n* [[How to] Disable tracking for a class or globally](https:\u002F\u002Fgithub.com\u002Fpokonski\u002Fpublic_activity\u002Fwiki\u002F%5BHow-to%5D-Disable-tracking-for-a-class-or-globally)\n* [[How to] Create custom activities](https:\u002F\u002Fgithub.com\u002Fpokonski\u002Fpublic_activity\u002Fwiki\u002F%5BHow-to%5D-Create-custom-activities)\n* [[How to] Use custom fields on Activity](https:\u002F\u002Fgithub.com\u002Fpokonski\u002Fpublic_activity\u002Fwiki\u002F%5BHow-to%5D-Use-custom-fields-on-Activity)\n\n## Help\n\nIf you need help with using public_activity please visit our discussion group and ask a question there:\n\nhttps:\u002F\u002Fgroups.google.com\u002Fforum\u002F?fromgroups#!forum\u002Fpublic-activity\n\nPlease do not ask general questions in the Github Issues.\n\n## License\nCopyright (c) 2011-2013 Piotrek Okoński, released under the MIT license\n","public-activity\u002Fpublic_activity 是一个为 ActiveRecord、Mongoid 3 和 MongoMapper 模型提供简便活动跟踪的 Ruby 库，类似于 GitHub 的公共活动功能。其核心功能包括记录模型的创建与变更，并支持将这些活动展示给用户。该库通过简单的配置即可实现对指定模型的活动跟踪，支持自定义活动类型和国际化，适用于需要向用户展示数据变动历史的应用场景，如新闻订阅、用户行为追踪等。基于 Rails 开发，易于集成到现有项目中，且提供了详尽的文档和示例来帮助开发者快速上手。",2,"2026-06-11 03:14:56","top_language"]