在 Rails 中编写用户通知代码的位置(如堆栈溢出中的堆栈交换)



我需要创建像facebook notificaiton这样的用户通知。

Manish sent you a friend request.

Ryan accepted your friend request.

在叠加div 中。

现在,我想问你在哪里(哪个控制器,我应该写代码)以及我应该如何aplication.html.haml看来。

注意:因为通知将显示在网站的所有页面中。

在应用程序控制器中编写代码,因为此代码应该是通用的并且适用于所有代码。在应用程序控制器中声明帮助程序方法,使其在视图中可访问。

它应该像以下作为一个总体思路——

    class ApplicationController < ActionController::Base
      protect_from_forgery
      helper_method :user_notifications
      private
      def user_notifications
       #your stuff here..
      end
    end

现在,在您的应用程序.html.erb 视图中,只需调用此方法。

最新更新