I am using Ruby on Rails 3 and I would like to implement some Rack middleware.
I know (but maybe I am wrong!) that, before of version 3, there was the Rails Metal "system" to handle those. But now?!
Where in my Rails application I have to locate files to use for middleware purposes (before of version 3, if I am not wrong, the folder was named 'metal')? then, ho开发者_如何学Pythonw I must state them in the application.rb
file?
Check out the Rails on Rack page on Rails Guides.
Your own middlewares can be stored in lib and can be required at the top of application.rb.
Checkout the following blog post, that may answer your question:
http://tektastic.com/2010/07/rails3-rack-and-where-did-my-metal-go.html
Check out this http://www.engineyard.com/blog/2010/rails-and-merb-merge-plugin-api-part-3-of-6/ for how to create a "Metal" controller
http://www.ruby-on-rails-outsourcing.com/articles/2010/05/28/how-to-create-your-own-rack-middleware-class-in-ruby-on-rails/ may be helpful for you.
It basically suggests to put your class in /lib/class_name.rb and then instruct it to be used like
Rails::Initializer.run do |config|
config.middleware.use "ClassName"
...
I believe you are right there is no more "metal" option in rails 3 http://tektastic.com/2010/07/rails3-rack-and-where-did-my-metal-go.html you have to use a rack middleware instead. I'm unsure if this causes a performance hit or not.
精彩评论