Get Extension by Mimetype in Rails

Sometimes we need to get an extension by content mime type. There are many ways to manage this but in Rails (or rack-based app) you can use this trick: 1 Rack::Mime::MIME_TYPES.invert['image/jpeg'] # => '.jpg'