Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

simple_notification

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple_notification

  • 0.0.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

SimpleNotification

SimpleNotification is a user notification system using tracked events. Event has a owner, recipient, trackable source, and a message.

Assumptions

SimpleNotification assumes a user systems is in place which uses the User model and has the current_user helper.

SimpleNotification also assumes that the Notification model is not taken.

Installation

Add this line to your application's Gemfile:

gem 'simple_notification'

And then execute:

$ bundle

Or install it yourself as:

$ gem install simple_notification

Usage

SimpleNotification generates the files in the /app folder, feel free to tweak it to fit specific needs.

First generate the necessary files:

$ rails g simple_notification

Add the routes for the view in /config/routes.rb:

resources :notifications

Add the following to /app/models/user.rb:

has_notifications

Add the following to any models that needs to be tracked:

can_be_tracked

And finally, add the following to /app/controllers/application_controller.rb:

include SimpleNotification::Methods

Now the setup is complete, the following are available:

Notifications generated by a user's activities:

@user.own_notifications

Notifications meant for a user:

@user.received_notifications

one can add .where(read: false) to obtain unread notifications

Method to notify a user of a tracked event:

notify(recipient, trackable, message)

which will generate a notification from current_user (guest if undefined) to the recipient with the message and trackable source.

Notifications are now working and can be displayed however desired, sample usages are:

render "notifications/show", notification_id: notification.id, read: false
render "notifications/show", notification_id: notification.id, read: true

Will will generate the following by default:

**Owner** message **Trackable** | This notification was sent to **Recipient** | Destroy

Contributing

  1. Fork it ( http://github.com//simple_notification/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

MIT License

FAQs

Package last updated on 17 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc