[Rails] Middleware example from Railscast #151 doesn't work as expected. Need help.
My middleware class "ResponseTimer" doesn't intercept a request. I don't
know why (the example is from here
http://railscasts.com/episodes/151-rack-middleware?view=asciicast; 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?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home