在Rails应用程序专用酒馆问题(Private pub issue in rails applic

2019-10-30 05:57发布

我有文章模型,我想表现出的通知,如主页上登录时,或谁被记录在已经当一个新的文章使用private_pub宝石贴在用户上的提示信息

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' %>

当我创建一个新的文章就成功创建,但没有发生任何通知

Answer 1:

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

你有有王菲的运行? rackup private_pub.ru -s thin -E production

假设你已经在按照说明https://github.com/ryanb/private_pub我想这调试的方式是开放的谷歌浏览器的控制台,并期待在底部的网络选项卡和WebSocket的应用程序,以查看是否连接了成立。 从那以后,我将推出rails console ,并派几个PrivatePub.publish_to('articles/new', article: 'hello world')看看他们是否会来在Chrome



文章来源: Private pub issue in rails application