0

Hey how to make a notification system like Facebook or diaspora in rails.

I had tried making activity feed but that was not the thing I wanted I want an exactly same feature like this websites have.

I have a simple app Where there are two types of users buyers and sellers

I want to notify the seller whenever a buyer comment on their products.

MZaragoza
  • 10,108
  • 9
  • 71
  • 116
Ahmed Reza
  • 293
  • 1
  • 3
  • 19

2 Answers2

2

What you are looking at here is a server push implementation. That means when some notification/action happens in the server, it should push a notification to your rails app. The difference with @manju's answer is, its proposing a a solution based on your clients browser will call the server periodically for new notifications.

There are two main ways to do this.

1 - Using some third party SASS solutions. (easy way, but cost money ;))

Fire base , allows you to send push notifications to clients.

pusher is another provider offers the same kind of functionalists.

Read their documentations, normally each of them have gems you can easily integrate to your rails app.

2 - Implement your own push server

You can implement your own push server with rails, and integrate to your app.

Faye is a one option,

But more exiting thing is Rails5 will have Action Cable which tries to solve the same issue. action cable gem

and there are articles showing action cable with rails4 apps (you dont have to wait till rails5 comes out) , but I haven't used it personally yet.

HTH

MZaragoza
  • 10,108
  • 9
  • 71
  • 116
sameera207
  • 16,547
  • 19
  • 87
  • 152
  • thanks @sameera207 . am not looking for a real time notification. i know it's stupid but yeah i want the user to refresh the browser to see new notifications. – Ahmed Reza Aug 10 '15 at 02:35
  • I think you wanted to use SAAS (Software As A Service) instead of SASS (CSS extension language) – Tun Jul 13 '16 at 15:05
1

Facebook does it using comet techniques.

Here are some of the helpful links

Link1

Link2

Link3

Here is the theory how facebook does

  • Facebook works by polling the server for any changes.

  • Facebook page will make ajax request to server and the ajax request will have much time out

  • But in the server-side in the API in server it will constantly poll DB server if anything has changed by constantly checking the activity log table in database ..if a change has been found it will return the result till then it will poll the DB

  • Once Ajax request is complete it will recursively try again.

Here is a code snippet - Client side

function doPoll() {
   $.get("events.php", {}, function(result) {
      $.each(result.events, function(event) { //iterate over the events
          //do something with your event
      });
      doPoll(); 
      //this effectively causes the poll to run again as
      //soon as the response comes back
   }, 'json'); 
}

$(document).ready(function() {
    $.ajaxSetup({
       timeout: 1000*60//set a global AJAX timeout of a minute
    });
    doPoll(); // do the first poll
});

Here is a code-snippet in server side:

while(!has_event_happened()) {
   sleep(5);
}

echo json_encode(get_events());

you can find it in much detail here

you can actually adopt this approach according to your needs

Community
  • 1
  • 1
Manju
  • 668
  • 7
  • 22
  • thanks @manju but i want something simple just notifications in a dropdown form.My needs are just that when a user comment on another user post they need to be notify with a number on the notification icon,with a notification in a drop-down for...sorry actually am a newbie that's why got in so much deep – Ahmed Reza Aug 09 '15 at 22:12
  • @Denialsmith - you can use the same logic...but let the API return number of comments and shows that in icon...that's it ...But logic is comet – Manju Aug 09 '15 at 22:19