我在我的 Rails 3.1 应用程序中使用了一个自定义的 Rack 中间件,它包裹了一个普通的 Rails 控制器:
在routes.rb
stacked_router =
Example::Middleware::StackedRouter.new(ProductsController.action(:show))
match '/:id', :to => stacked_router
在example/middleware/stacked_router.rb
class Example::Middleware::StackedRouter
def initialize(app)
@app = app
end
def call(env)
# ... do stuff before forwarding the request, then
@app.call(env) # forward the request
end
end
这工作正常。
但是有一个问题:当我现在更改代码时ProductsController
,不会自动获取更改。我必须手动重新启动应用程序 ( touch tmp/restart.txt
)
有什么方法可以告诉 Rails 堆栈在代码更改时需要重新加载这个中间件?