snowleopard
snowleopard

Reputation: 833

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

Upvotes: 3

Views: 1379

Answers (1)

snowleopard
snowleopard

Reputation: 833

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

Upvotes: 4

Related Questions