Immo
Immo

Reputation: 601

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 here enter image description here

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

Thanks

Upvotes: 5

Views: 1719

Answers (1)

tadman
tadman

Reputation: 211540

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.

Upvotes: 6

Related Questions