2013-07-05 30 views
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' %> 
当我创建一个新的文章就成功创建,但没有发生

没有通知

回答

1

已包含在你的application.js //= require private_pub

您是否已经运行了faye? rackup private_pub.ru -s thin -E production

假设您已按照https://github.com/ryanb/private_pub的指示操作,我将调试该方法的方式是在Google Chrome控制台中打开该应用程序,并查看底部的网络选项卡和websocket以查看是否建立了连接。从那以后,我将推出rails console和派几个PrivatePub.publish_to('articles/new', article: 'hello world'),看看他们是否会来在Chrome

+0

网络选项卡和WebSocket的不显示“王菲”,但rackup命令似乎没有任何问题推出,我很困惑 –

+0

我有同样的问题。当我检查谷歌铬控制台。它似乎是在'private_pub.yml'+ .js文件中搜索'服务器值。不知道为什么它附加.js –

+0

特别是,我已经离开PrivatePub并决定使用SockJS并将自己的nodejs websocket服务器与Rails集成(PrivatePub无法在iOS中正常工作)。如果您仍然在使用PrivatePub,那么开发人员不再支持它。另一种方法是将PrivatePub的一个分支称为d'Anthèshttps://github.com/dotpromo/danthes – user1894919