ruby-on-rails – 未定义PrivatePub错误Rails 3.2私人酒吧
发布时间:2020-12-17 03:22:53 所属栏目:百科 来源:网络整理
导读:我想在我的rails应用程序中使用私有pub gem.我用railscast 316实现 在rails g private_pub之后:安装 我的private_pub.yml文件: development: server: "http://0.0.0.0:9292/faye" secret_token: "secret"test: server: "http://0.0.0.0:9292/faye" secret_
我想在我的rails应用程序中使用私有pub gem.我用railscast 316实现
在rails g private_pub之后:安装 我的private_pub.yml文件: 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 我的private_pub.ru文件 # 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 } 我的索引文件 <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" %> 控制器文件: def create params[:mesaj][:gonderen_id]= current_kullanici.id @mesaj = Mesaj.create!(params[:mesaj]) PrivatePub.publish_to("/mesajlar/new","alert('#{@mesaj.icerik}');") end 我将// = require private_pub添加到application.js文件中 页面初始化后,我在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> Rails日志中没有输出和RAILS_ENV =生产包exec rackup private_pub.ru -s thin -E生产命令日志 我搜索过,没有找到解决方案. 问题出在哪儿? 解决方法
我发现问题,我会写解决方案因为其他人应该得到这个错误:
我的javascripts被置于底部 <%= subscribe_to "/mesajlar/new" %> line calling before private_pub.js is loaded. 所以, <% content_for :bottom do %> <%= subscribe_to "/mesajlar/new" %> <% end %> 可以解决这个问题. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |