简体   繁体   中英

The Rails Metal in Ruby on Rails 3

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, how 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM