【发布时间】:2013-01-24 02:36:54
【问题描述】:
假设变量content_type = "application/pdf" 也可以包含任何其他mime 类型。
如何获取内容类型的默认扩展名?
我目前有两种解决方案,看起来很“复杂”。
破解字符串
content_type.split("/")[1]
使用 MIME::Types
require 'mime/types'
MIME::Types[content_type].first.extensions.first
有没有更好的解决方案?
【问题讨论】:
-
使用了你的第二个解决方案,效果很好。顺便说一句,在 Rails 应用程序中,我不需要 mime/types。
标签: ruby-on-rails ruby