我有文章模型,我想在用户登录或使用 private_pub gem 发布新文章时向用户显示主页上的 Flash 消息等通知
文章控制器.rb
class ArticlesController < ApplicationController
def index
@articles = Article.all
@articles_grid = initialize_grid(Article,
:include => [:user])
end
def show
@article = Article.find(params[:id])
@comment = Comment.new
end
def new
@article = Article.new
end
def create
@article = Article.new(params[:article])
@article.user_id = current_user.id
if @article.save
redirect_to articles_url, notice: 'Created article.'
PrivatePub.publish_to('articles/new', article: @article)
else
render :new
end
end
def edit
@article = Article.find(params[:id])
end
def update
@article = Article.find(params[:id])
if @article.update_attributes(params[:article])
redirect_to articles_url, notice: 'Updated article.'
else
render :edit
end
end
end
文章.js.coffee
PrivatePub.subscribe 'articles/new',(data, channel) ->
alert data.article.content
在我的 static_pages/home.html.erb
<%= subscribe_to '/articles/new' %>
当我创建一篇新文章时,它创建成功但什么也没有发生没有通知