I looked at some of the answers 1] Include in qoutes, 2] Dont use require etc but neither of them works. Its possible the solution has changed in Rails4
I am trying to follow the tutorial here https://devcenter.heroku.com/articles/ruby-websockets#using-with-rails
It says Copy the existing ChatBackend middleware to app/middleware/chat_backend.rb in your Rails project. Then insert the middleware into your stack, defined in config/application.rb:
require 'chat_backend'
config.middleware.use ChatDemo::ChatBackend
I have the middleware defined in app/middlewares/chat_backend.rb as follows:
require 'faye/websocket'
require 'thread'
require 'redis'
require 'json'
require 'erb'
module ChatDemo
class ChatBackend
KEEPALIVE_TIME = 15 # in seconds
CHANNEL = 'twitter-stream'
def initialize(app)
end
/// DELETED CODE for simplicity
end
Here is the application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
require 'chat_backend' <= ERROR: config/application.rb:4:in `require': cannot load such file -- chat_backend (LoadError)
Bundler.require(*Rails.groups)
module MyProject
class Application < Rails::Application
config.middleware.use ChatDemo::ChatBackend
end
end
How exactly do I add the middleware. Appreciate any exact code samples.