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.
Can someone provide an example or a tutorial on how to create that in Ruby on Rails or Javascript/jQuery?
开发者_如何学CThanks
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.
精彩评论