My middleware class "ResponseTimer" doesn't intercept a request. I don't know why (the example is from here #151 Rack Middleware - RailsCasts; I changed my one a little for Rails 3.2.13 version, the original is for Rails 2.x).
So I did as follows:
## in \lib\response_timer.rb ## this is the class of my custom middleware:
class ResponseTimer def initialize(app) @app = app end
def call(env) [200, {"Content-Type" => "text/html"}, "Hello, World!"] end end
## in \config\initializers\custom_middleware.rb ## this is an initializer file that I created. It's goal is to add my ## middleware "ResponseTimer" to the middleware stack:
module Demo class Application < Rails::Application config.after_initialize do Rails.application.config.middleware.insert_after(ActionDispatch::Callbacks, "ResponseTimer") end end end
Now I check whether "ResponseTimer" is in the middleware stack, and it is: C:\myapp>rake middleware ... use ActionDispatch::Callbacks use ResponseTimer ## ok, it is in the middleware stack use ActiveRecord::ConnectionAdapters::ConnectionManagement ...
But when I make a request my "ResponseTimer" doesn't intercept it. The request successfully passes by to the application. Instead of ResponseTimer's "Hello World!" response I get standard response:
Hello#index Find me in app/views/hello/index.html.erb
What do I do wrong? What did I forget to set or enable?