SQLTerminal.app
now available

XPath.app
now available
Want fresh tech tips in your inbox?

How To Get A List of All Registered Mime Types in Rails

       

When mime types are registered they are placed in a hash constant EXTENSION_LOOKUP in the module Mime. For reference, the file with the relevant code is in rails/action_pack/lib/action_dispatch/http/mime_type.rb available on Github at https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/mime_type.rb

You can check for existence of certain mime types with

Mime::Type.lookup_by_extension(:json)
which will return the object or nil if it's not registered. You can also iterate over all registered mime types by cycling through the constant like so
Mime::EXTENSION_LOOKUP.each { |m| puts m}

Api documentation is here: http://api.rubyonrails.org/classes/Mime/Type.html#method-c-lookup_by_extension

Tagged w/ #content types #mime types #rails core #rails source #respondersrails source

Apps I've Built

XPath Expression Editor
Practice and improve your XPath skills with XPath Editor
Click to buy on the App Store
Photo Location Changer
Easily change the location on your photos and videos
Click here for more info about the app
Photo Date Changer
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app