PrivatePub 未定义错误 Rails 3.2 private pub [英] PrivatePub is not defined error Rails 3.2 private pub

查看:36
本文介绍了PrivatePub 未定义错误 Rails 3.2 private pub的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 rails 应用程序中使用私有 pub gem.我用 railscast 316 实现

rails g private_pub:install

之后

我的 private_pub.yml 文件:

开发:服务器:http://0.0.0.0:9292/faye"secret_token:秘密"测试:服务器:http://0.0.0.0:9292/faye"secret_token:秘密"生产:服务器:http://0.0.0.0/faye"secret_token:98ec77eb7077c9899dc53f003abc4d6a0170512a57feab126ed5a32b114e3613"signature_expiration: 3600 # 一小时

我的 private_pub.ru 文件

 # 运行:rackup private_pub.ru -s thin -E production需要捆绑程序/设置"需要yaml"需要faye"需要private_pub"Faye::WebSocket.load_adapter('瘦')PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")运行 PrivatePub.faye_appFaye::Logging.log_level = :debugFaye.logger = lambda { |m|把 m }

我的索引文件

聊天

<ul id="聊天"><%= 渲染@mesajlar %><%= form_for Mesaj.new, remote: true do |f|%><%= f.text_field :icerik %><%= f.submit "发送" %><%结束%><%= subscribe_to "/mesajlar/new" %>

控制器文件:

def 创建参数[:mesaj][:gonderen_id]= current_kullanici.id@mesaj = Mesaj.create!(params[:mesaj])PrivatePub.publish_to("/mesajlar/new", "alert('#{@mesaj.icerik}');")结尾

我将 //= require private_pub 添加到 application.js 文件

页面初始化后,我在 firebug 上收到以下错误:

**PrivatePub 未定义**在<script type="text/javascript">PrivatePub.sign({"server":"http://0.0.0.0:9292","timestamp":1363853952047,"channel":"/mesajlar/new","签名":"7bf74474796412b524b6c6c8849c50cb245ce92d"});</script>

Rails 日志和 RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production 命令日志中没有输出

我搜索过,没有找到解决方案.

问题出在哪里?

解决方案

我找到了问题,我会写解决方案,因为其他人都会遇到这个错误:

我的 javascripts 放在底部所以

<%= subscribe_to "/mesajlar/new" %>加载 private_pub.js 之前的行调用.

所以,在索引文件中

<% content_for :bottom do %><%= subscribe_to "/mesajlar/new" %><%结束%>

应该可以解决这个问题.

I want to use private pub gem in my rails application. I implement with railscast 316

After rails g private_pub:install

my private_pub.yml file:

development:
  server: "http://0.0.0.0:9292/faye"
  secret_token: "secret"
test:
  server: "http://0.0.0.0:9292/faye"
  secret_token: "secret"
production:
  server: "http://0.0.0.0/faye"
  secret_token: "98ec77eb7077c9899dc53f003abc4d6a0170512a57feab126ed5a32b114e3613"
  signature_expiration: 3600 # one hour

my private_pub.ru file

    # Run with: rackup private_pub.ru -s thin -E production
    require "bundler/setup"
    require "yaml"
    require "faye"
    require "private_pub"

    Faye::WebSocket.load_adapter('thin')

    PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
    run PrivatePub.faye_app

Faye::Logging.log_level = :debug
Faye.logger = lambda { |m| puts m }

my index file

<h1>Chat</h1>

<ul id="chat">
  <%= render @mesajlar %>
</ul>

<%= form_for Mesaj.new, remote: true do |f| %>
    <%= f.text_field :icerik %>
    <%= f.submit "Send" %>
<% end %>

<%= subscribe_to "/mesajlar/new" %>

Controller file:

def create
params[:mesaj][:gonderen_id]= current_kullanici.id
@mesaj = Mesaj.create!(params[:mesaj])
PrivatePub.publish_to("/mesajlar/new", "alert('#{@mesaj.icerik}');")
end 

I add //= require private_pub to application.js file

After the page was initialized I get the error below on firebug:

**PrivatePub is not defined**
at 
<script type="text/javascript">PrivatePub.sign({"server":"http://0.0.0.0:9292","timestamp":1363853952047,"channel":"/mesajlar/new","signature":"7bf74474796412b524b6c6c8849c50cb245ce92d"});</script>
</div> 

And no output in Rails log and RAILS_ENV=production bundle exec rackup private_pub.ru -s thin -E production commands log

I searched and no found a solution.

Where is the problem?

解决方案

I find the problem, I will write solution because anyone else should get this error:

My javascripts is placed in bottom so

<%= subscribe_to "/mesajlar/new" %> line calling before private_pub.js is loaded.

So, in index file

<% content_for :bottom do %>
<%= subscribe_to "/mesajlar/new" %>
<% end  %>

sould solve this.

这篇关于PrivatePub 未定义错误 Rails 3.2 private pub的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆