I am using a custom Rack middleware in my Rails 3.1 app that wraps around a vanilla Rails controller:
in routes.rb
stacked_router =
Example::Middleware::StackedRouter.new(ProductsController.action(:show))
match '/:id', :to => stacked_router
in 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
This works fine.
However there is a catch: When I now change code in ProductsController, the changes are not picked up automatically. I have to restart the app manually (touch tmp/restart.txt)
What's the way to tell the Rails stack that it needs to reload this piece of middleware whenever code is changed?
If you are using Pow you can use the powder gem to easily restart Pow without the need to execute touch
tmp/restart.txtcommand. See https://github.com/Rodreegez/powder.