简体   繁体   English

Ruby on Rails中的通知栏

[英]Notification bar in Ruby on Rails

I would like to create a Notification Bar similar to Facebook or StackExchange. 我想创建一个类似于Facebook或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? 有人可以提供一个示例或教程来说明如何在Ruby on Rails或Javascript / jQuery中创建它吗?

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. 添加一个jQuery处理程序,该处理程序将根据偏好通过单击或悬停通过AJAX加载消息。

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: 下一部分涉及使用jQuery将某些东西修补在一起,也许像这样:

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

You'll need to have a specific view that will render into that #notification block. 您需要有一个特定的视图,该视图将渲染到该#notification块中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM