Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save awesome/52ad7c7c7fca41e544c7546f4eddf125 to your computer and use it in GitHub Desktop.
Save awesome/52ad7c7c7fca41e544c7546f4eddf125 to your computer and use it in GitHub Desktop.
How To Get A List of All Registered Mime Types in Rails
# via http://www.seanbehan.com/how-to-get-a-list-of-all-registered-mime-types-in-rails/
#
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment