问题
Many examples such as these two:
How to use rack middleware with Rails3?
http://asciicasts.com/episodes/151-rack-middleware
define middleware in a class and then add
config.middleware.use "ClassNameHere"
to config/application.rb
but I can't figure where in application.rb to add this. I have put it inside of class Application < Rails::Application
. I am also not sure if there is a specific location where I put my middleware class. I have mine in /lib.
Say my middleware class is called ResponseTimer, I receive the following error when I run rake middleware
:
uninitialized constant ResponseTimer
Please note that I am in Rails 3.1 and not 2.x which is why I am not putting the config.middleware.use in environment.rb
回答1:
add config.autoload_paths += %W(#{config.root}/lib)
to config/application.rb
See here https://github.com/radar/guides/blob/master/rails-lib-files.md
来源:https://stackoverflow.com/questions/11478920/rails-3-how-to-declare-rack-middleware-in-application-rb