ryanb / private_pub

Handle pub/sub messaging through private channels in Rails using Faye.
MIT License
863 stars 226 forks source link

setup problem on simple subscribe #41

Closed bl4d3 closed 12 years ago

bl4d3 commented 12 years ago

Hi, I have a problem to biuld up a simple notification system as Ryan has pointed in its railscast. I have this in my view

<%= form_for Bet.new, :remote => true do |f| %>
  <div id="auction_<%= auction.id %>"></div>
    <%= text_field_tag "bet[auction_id]", auction.id %>
    <%= f.submit "Bet" %>
  </div>
<% end %>
<%= subscribe_to "bets/new" %>

this is the create action for bets controller:

  def create
    @auction = Auction.find(params[:bet][:auction_id])
    @bet = Bet.new(params[:bet])
    @bet.save
  end

and I have this in create.js.erb

<% publish_to "bets/new" do %>
  alert("done");
<% end %>

I aspect that all the client show the alert, but nothing happen, in my development.log I have

Started POST "/bets" for 127.0.0.1 at 2012-03-03 12:12:01 +0100
Processing by BetsController#create as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"6aCKDrymUu2aaRuWO9AIJOR+2p/fo5ZNEdCfBN9w7ZA=", "bet"=>{"auction_id"=>"1"}, "commit"=>"Bet"}
  Auction Load (0.4ms)  SELECT `auctions`.* FROM `auctions` WHERE `auctions`.`id` = 1 LIMIT 1
   (0.1ms)  BEGIN
   (0.1ms)  ROLLBACK
  Rendered bets/create.js.erb (3.0ms)

if it can help, my private_pub.ru

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

a strange thing happen after i started thin with "rackup private_pub.ru -s thin -E production" I'm keep getting this 2012-03-03 12:31:15 [ERROR] [Faye::RackAdapter] undefined method []' for nil:NilClass Backtrace: /Users/mattialipreri/.rvm/gems/ruby-1.9.2-p290/gems/faye-0.8.0/lib/faye/adapters/rack_adapter.rb:137:inblock in handle_websocket' /Users/mattialipreri/.rvm/gems/ruby-1.9.2-p290/gems/faye-websocket-0.4.1/lib/faye/websocket/api/event_target.rb:24:in call' /Users/mattialipreri/.rvm/gems/ruby-1.9.2-p290/gems/faye-websocket-0.4.1/lib/faye/websocket/api/event_target.rb:24:indispatch_event' Any hint about the issue? Thanks

zlu commented 12 years ago

This is a bug introduced in Faye 0.8.0: https://groups.google.com/forum/?fromgroups#!topic/faye-users/QqIazim8MXo

The fix will be out with Faye0.8.1.

In the meanwhile, the easiest thing to do is to revert to an older Faye Gem (0.7.1).

Since Faye 0.8.0 introduced two incompatible changes, it breaks PrivatePub gem as it doesn't specify the version of Faye. I've sent a pull request to @ryanb and am working a Faye 0.8.0 compatibility fix.

bl4d3 commented 12 years ago

thanks many, I'll try ASAP, I spent a weekend looking for the reason of it, good to know.

bl4d3 commented 12 years ago

I confirm that with faye 0.7.1 works fine.