Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 964
snowleopard Avatar asked Dec 31 '25 19:12

snowleopard


1 Answers

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

like image 181
snowleopard Avatar answered Jan 06 '26 07:01

snowleopard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!