Wins Lin
2013-May-13 21:46 UTC
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.erbWhat 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Reasonably Related Threads
- Error reverse engineering MySQL with RMRE
- Can't use ActionDispatch::Request in Rails middleware because path_parameters get lost
- How to handle exception that is generated in rack middleware before it reach rails app?
- Rack Middleware support for Rails 2.0.2? If not what is the alternative to implement similar functionality in Rails 2.0.2..
- uninitialized constant ActionController::Flash::FlashHash [NameError])