Coder Social home page Coder Social logo

eric-guo / notifications Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rails-engine/notifications

0.0 3.0 0.0 188 KB

Notifications Center engine like GitHub or other application for any Rails applications.

License: MIT License

Ruby 77.78% CSS 5.17% HTML 16.17% JavaScript 0.88%

notifications's Introduction

Notifications

Rails mountable Notification for any applications.

Gem Version Build Status Code Climate codecov.io

Example:

2016-03-29 10 48 16

Installation

# Gemfile
gem 'notifications'

And then run bundle install.

Now you have notifications generator in Rails application:

$ rails g notifications:install

And, you can generate views, controller if you need custom them:

$ rails g notifications:views
$ rails g notifications:controllers

Usage

Create a Notification

class User
  def follow(user)
    Notification.create(notify_type: 'follow', actor: self, user: user)
  end
end

class Comment
  belongs_to :post
  belongs_user :user

  after_commit :create_notifications, on: [:create]
  def create_notifications
    Notification.create(
      notify_type: 'comment',
      actor: self.user,
      user: self.post.user,
      target: self)
  end
end

Get user unread count:

count = Notification.unread_count(current_user)

Write your custom Notification partial view for notify_types:

If you create a notify_type, you need add a partial view in app/views/notifications/ path, for example:

# There have two notify_type
Notification.create(notify_type: 'follow' ....)
Notification.create(notify_type: 'mention', target: @reply, second_target: @topic, ....)

You app must be have:

  • app/views/notifications/_follow.html.erb
  • app/views/notifications/_mention.html.erb
# app/views/notifications/_follow.html.erb
<div class="media-heading">
  <%= link_to notification.actor.title, notification.actor %> just followed you.
</div>
# app/views/notifications/_mention.html.erb
<div class="media-heading">
  <%= link_to notification.actor.title, notification.actor %> has mention you in
  <%= link_to notification.second_target.title, topic_path(notification.second_target) %>
</div>
<div class="media-content">
  <%= notification.target.body %>
</div>

About Notification template N+1 performance

We suggest use second_level_cached for solve N+1 performance issue.

Contributing

Contribution directions go here.

Site Used

License

The gem is available as open source under the terms of the MIT License.

notifications's People

Contributors

huacnlee avatar eric-guo avatar

Watchers

James Cloos avatar  avatar  avatar

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.