Rails 3: How to declare Rack middleware in application.rb

只愿长相守 提交于 2020-01-02 07:11:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!