0
我有文章模型,我想在主页上向用户显示通知,例如主页上的Flash消息,或者在使用private_pub发布新文章时已经登录的用户宝石在rails应用程序中的私人酒吧问题
articles_controller.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
articles.js.coffee
PrivatePub.subscribe 'articles/new',(data, channel) ->
alert data.article.content
在我static_pages/home.html.erb
<%= subscribe_to '/articles/new' %>
当我创建一个新的文章就成功创建,但没有发生
没有通知
网络选项卡和WebSocket的不显示“王菲”,但rackup命令似乎没有任何问题推出,我很困惑 –
我有同样的问题。当我检查谷歌铬控制台。它似乎是在'private_pub.yml'+ .js文件中搜索'服务器值。不知道为什么它附加.js –
特别是,我已经离开PrivatePub并决定使用SockJS并将自己的nodejs websocket服务器与Rails集成(PrivatePub无法在iOS中正常工作)。如果您仍然在使用PrivatePub,那么开发人员不再支持它。另一种方法是将PrivatePub的一个分支称为d'Anthèshttps://github.com/dotpromo/danthes – user1894919