Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification bar in Ruby on Rails

I would like to create a Notification Bar similar to Facebook or StackExchange.

I want it to display notifications with numbers and a drop down panel with some information.

enter image description hereenter image description here

Can someone provide an example or a tutorial on how to create that in Ruby on Rails or Javascript/jQuery?

Thanks

like image 814
Immo Avatar asked Aug 02 '11 18:08

Immo


1 Answers

It's probably done as a two stage process:

  • Get a counter of outstanding/unread notifications. Display in header as a link.
  • Add a jQuery handler that will load the messages via AJAX either on click or on hover depending on preferences.

The first part is simple, you just call a method on your association if you have a scope established:

<%= link_to(@user.notifications.unread.count, user_notifications_path(@user), :class => 'notifications') %>

The next part involves patching together something with jQuery, perhaps like this:

$('.notifications').click(function() {
  $('#notifications').load(this.href);
  return false;
});

You'll need to have a specific view that will render into that #notification block.

like image 71
tadman Avatar answered Sep 24 '22 18:09

tadman