validates_attachment_content_type
为了能够上传代码文件,应该进行什么配置。就我而言,我想上传 .R 文件。
我想做这样的事情:
class RFile < ActiveRecord::Base
has_attached_file :r, url: "/system/:attachment/:id/:basename.:extension"
validates_attachment_content_type :r, content_type: 'text/r'
end
我必须定义一个 mime 类型吗?我该怎么做?
编辑:
使用此代码,使用text/plain
:
class RFile < ActiveRecord::Base
has_attached_file :r, url: "/system/:attachment/:id/:basename.:extension"
validates_attachment_content_type :r, content_type: 'text/plain'
end
我收到以下错误:
R has contents that are not what they are reported to be
R is invalid
R content type is invalid
我查看了这个 mime 类型列表
http://hul.harvard.edu/ois/systems/wax/wax-public-help/mimetypes.htm
但我没有找到 .R 文件的那个。但是在执行这个命令时:
file --mime-type compare_datasets.R
我得到这个结果:
compare_datasets.R: text/plain
为什么text/plain
不起作用?