I am trying to accomplish the following task: as soon a post is approved on the site, people on this site will be informed of that.
To solve this I am using Faye, and publishing on the channel on my method approve. My application has only one channel, really simple scenario. Anyway, for some reason it is not working.
I am using Rails 2.3.5, Faye 0.8.5, eventmachine 1.0.0.beta4 (the one installed with Faye), rack 1.0.1, and thin 1.3.1. I am not using Apache.
What I have so far is:
faye.ru: (I run it with: rackup faye.ru -s thin -E production)
require 'faye'
faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
run faye_server
application.js:
var $j = jQuery.noConflict();
$j(function() {
var faye = new Faye.Client('http://0.0.0.0:9292/faye');
faye.subscribe("/messages/new", function(data) {
alert(data.text);
});
});
application.html.erb:
<%= javascript_include_tag 'http://0.0.0.0:9292/faye.js' %>
posts_controller.rb:
def approve
@post.update_attribute(:approved, true)
message = {:post => @post}
uri = URI.parse("http://0.0.0.0:9292/faye")
Net::HTTP.post_form(uri, :message => message.to_json)
redirect_to(pending_posts_path)
end
The stack trace is:
EOFError (end of file reached):
/usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread'
/usr/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/usr/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
/usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
/usr/lib/ruby/1.8/net/protocol.rb:126:in `readline'
/usr/lib/ruby/1.8/net/http.rb:2024:in `read_status_line'
/usr/lib/ruby/1.8/net/http.rb:2013:in `read_new'
/usr/lib/ruby/1.8/net/http.rb:1050:in `request'
/usr/lib/ruby/1.8/net/http.rb:405:in `post_form'
/usr/lib/ruby/1.8/net/http.rb:543:in `start'
/usr/lib/ruby/1.8/net/http.rb:404:in `post_form'
app/controllers/posts_controller.rb:38:in `approve'
And on the thin server an error also appears:
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
!! Unexpected error while processing request: undefined method `call' for nil:NilClass
As far as I understood, this error appears everytime I try to connect on the server, and a critical thing is that "http://0.0.0.0:9292/faye.js" is not available, i.e., if I try to access this URL, I receive "!! Unexpected error while processing request: undefined method `call' for nil:NilClass", and that is the same reason why Net:HTTP can't access it. I would like to know why.