开发者

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.

Notification bar in Ruby on Rails

Notification bar in Ruby on Rails

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

开发者_如何学C

Thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜