{"id":13879296,"url":"https://github.com/rails-engine/notifications","last_synced_at":"2025-04-07T03:19:39.717Z","repository":{"id":53574843,"uuid":"54863321","full_name":"rails-engine/notifications","owner":"rails-engine","description":"🛎 Notifications Center engine like GitHub or other application for any Rails applications.","archived":false,"fork":false,"pushed_at":"2024-09-27T15:18:08.000Z","size":250,"stargazers_count":387,"open_issues_count":3,"forks_count":41,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-06T07:41:30.504Z","etag":null,"topics":["notification","notification-center","notifications","rails-engine"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rails-engine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-28T03:39:29.000Z","updated_at":"2025-01-21T17:26:48.000Z","dependencies_parsed_at":"2025-01-05T15:15:07.914Z","dependency_job_id":null,"html_url":"https://github.com/rails-engine/notifications","commit_stats":{"total_commits":74,"total_committers":6,"mean_commits":"12.333333333333334","dds":0.06756756756756754,"last_synced_commit":"c989ec6e6b13622705800dc8742caac260bff023"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rails-engine%2Fnotifications","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rails-engine%2Fnotifications/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rails-engine%2Fnotifications/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rails-engine%2Fnotifications/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rails-engine","download_url":"https://codeload.github.com/rails-engine/notifications/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247584112,"owners_count":20962075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["notification","notification-center","notifications","rails-engine"],"created_at":"2024-08-06T08:02:16.509Z","updated_at":"2025-04-07T03:19:39.689Z","avatar_url":"https://github.com/rails-engine.png","language":"Ruby","funding_links":[],"categories":["Ruby","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Notifications\n\nMountable notifications for any Rails applications.\n\n[![Gem Version](https://badge.fury.io/rb/notifications.svg)](https://badge.fury.io/rb/notifications) [![Build Status](https://travis-ci.org/rails-engine/notifications.svg)](https://travis-ci.org/rails-engine/notifications) [![codecov.io](https://codecov.io/github/rails-engine/notifications/coverage.svg?branch=master)](https://codecov.io/github/rails-engine/notifications?branch=master)\n\n## Example:\n\n\u003cimg width=\"800\" alt=\"2016-03-29 10 48 16\" src=\"https://cloud.githubusercontent.com/assets/5518/16578955/eb59e472-42cf-11e6-825e-8fc9ecf58a8b.png\"\u003e\n\n## Installation\n\n```bash\n$ bundle add notifications\n```\n\nYou now have a notifications generator in your Rails application:\n\n```bash\n$ rails g notifications:install\n```\n\nYou can generate views, controllers if you need to customize them:\n\n```bash\n$ rails g notifications:views\n$ rails g notifications:controllers\n```\n\n## Usage\n\n### Create a Notification\n\n```ruby\nclass User\n  def follow(user)\n    Notification.create(notify_type: 'follow', actor: self, user: user)\n  end\nend\n\nclass Comment\n  belongs_to :post\n  belongs_to :user\n\n  after_commit :create_notifications, on: [:create]\n  def create_notifications\n    Notification.create(\n      notify_type: 'comment',\n      actor: self.user,\n      user: self.post.user,\n      target: self)\n  end\nend\n```\n\nGet unread notifications count for a user:\n\n```rb\n# unread count\nunread_count = Notification.unread_count(current_user)\n\n# read count\nread_count = Notification.read_count(current_user)\n\n```\n\n```rb initialize/**.rb\n# for non-user class\nNotifications.config.user_class = 'Member'\n\n#or change\n\nNotifications.configure do\n  # Class name of you User model, default: 'User'\n  self.user_class = 'User'\n\n  # Method of user name in User model, default: 'name'\n  # self.user_name_method = 'name'\n\n  # Method of user avatar in User model, default: nil\n  # self.user_avatar_url_method = nil\n\n  # Method name of user profile page path, in User model, default: nil\n  # self.user_profile_url_method = 'profile_url'\n\n  # authenticate_user method in your Controller, default: nil\n  # If you use Devise, authenticate_user! is correct\n  # self.authenticate_user_method = 'authenticate_user!'\n\n  # current_user method name in your Controller, default: 'current_user'\n  # If you use Devise, current_user is correct\n  # self.current_user_method = 'current_user'\nend\n\n\n```\n\n### Write your custom Notification partial view for notify_types:\n\nIf you create a notify_type, you need to add a partial view in `app/views/notifications/` path, for example:\n\n```rb\n# There have two notify_type\nNotification.create(notify_type: 'follow' ....)\nNotification.create(notify_type: 'mention', target: @reply, second_target: @topic, ....)\n```\n\nYour app must have:\n\n- app/views/notifications/_follow.html.erb\n- app/views/notifications/_mention.html.erb\n\n```erb\n# app/views/notifications/_follow.html.erb\n\u003cdiv class=\"media-heading\"\u003e\n  \u003c%= link_to notification.actor.title, main_app.user_path(notification.actor) %\u003e just followed you.\n\u003c/div\u003e\n```\n\n```erb\n# app/views/notifications/_mention.html.erb\n\u003cdiv class=\"media-heading\"\u003e\n  \u003c%= link_to notification.actor.title, main_app.user_path(notification.actor) %\u003e has mentioned you in\n  \u003c%= link_to notification.second_target.title, main_app.topic_path(notification.second_target) %\u003e\n\u003c/div\u003e\n\u003cdiv class=\"media-content\"\u003e\n  \u003c%= notification.target.body %\u003e\n\u003c/div\u003e\n```\n\n\u003e NOTE: When you want use Rails route path name in notification views, you must use [main_app](http://api.rubyonrails.org/classes/Rails/Engine.html#class-Rails::Engine-label-Using+Engine-27s+routes+outside+Engine) prefix. etc: `main_app.user_path(user)`\n\n### About Notification template N+1 performance\n\nIt is recommended that you use [second_level_cache](https://github.com/hooopo/second_level_cache) for solving N+1 performance issues.\n\n## Contributing\n\nTesting for multiple Rails versions:\n\n```bash\nmake test_51\n# or test all\nmake test\n```\n\n## Site Used\n\n- [Ruby China](https://ruby-china.org)\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frails-engine%2Fnotifications","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frails-engine%2Fnotifications","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frails-engine%2Fnotifications/lists"}