[英]Cannot load Rack Middleware file into Rails app
Trying to get Heroku's WebSocket tutorial working with a Rails app but the middleware is not loading. 试图让Heroku的WebSocket教程与Rails应用一起工作,但中间件未加载。
Steps to reproduce: 重现步骤:
faye-websocket
gem and run bundle install
faye-websocket
gem并运行bundle install
app/middleware
directory in the application app/middleware
目录 app/middleware/test_server.rb
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
config/application.rb
config/application.rb
config.middleware.use TestServer
config.middleware.use TestServer
rails console
rails console
I see the following error: 我看到以下错误:
config/application.rb:64:in `': uninitialized constant RackMiddleware::Application::TestServer (NameError)
config / application.rb:64:in`':未初始化的常量RackMiddleware :: Application :: TestServer(NameError)
If I add require 'test_server'
, I see the following error: 如果添加
require 'test_server'
, require 'test_server'
看到以下错误:
config/application.rb:5:in `require': cannot load such file -- test_server (LoadError)
config / application.rb:5:在'require'中:无法加载这样的文件-test_server(LoadError)
I thought an directories in app/
were automatically added in Rails 3. What am I doing wrong? 我以为
app/
中的目录已自动添加到Rails 3中。我在做什么错?
Looks like the problem is that the TestServer has to be in quotes for config.middleware.use
call. 看起来问题在于TestServer必须在
config.middleware.use
调用的引号中。
The answer here helped: https://stackoverflow.com/a/16206347/3467 答案在这里有所帮助: https : //stackoverflow.com/a/16206347/3467
The Heroku howto is incorrect, sent them an comment to fix it. Heroku howto错误,向他们发送了评论以对其进行修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.