Question

Trying to get Heroku's WebSocket tutorial working with a Rails app but the middleware is not loading.

Steps to reproduce:

  • Created a Rails 3.2.15 app.
  • Add faye-websocket gem and run bundle install
  • Create app/middleware directory in the application
  • Copy over the the following into app/middleware/test_server.rb
require 'faye/websocket'

class TestServer
  KEEPALIVE_TIME = 15 # in seconds

  def initialize(app)
    @app     = app
    @clients = []
  end

  def call(env)
  end
end
  • Add the following to config/application.rb

config.middleware.use TestServer

  • Run rails console

I see the following error:

config/application.rb:64:in `': uninitialized constant RackMiddleware::Application::TestServer (NameError)

If I add require 'test_server', I see the following error:

config/application.rb:5:in `require': cannot load such file -- test_server (LoadError)

I thought an directories in app/ were automatically added in Rails 3. What am I doing wrong?

Was it helpful?

Solution

Looks like the problem is that the TestServer has to be in quotes for config.middleware.use call.

The answer here helped: https://stackoverflow.com/a/16206347/3467

The Heroku howto is incorrect, sent them an comment to fix it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top