【发布时间】:2016-03-09 15:01:18
【问题描述】:
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 不起作用?
【问题讨论】:
标签: ruby-on-rails r ruby-on-rails-4 paperclip paperclip-validation