Ruby on rails 用回形针上传代码文件
什么应该是Ruby on rails 用回形针上传代码文件,ruby-on-rails,r,ruby-on-rails-4,paperclip,paperclip-validation,Ruby On Rails,R,Ruby On Rails 4,Paperclip,Paperclip Validation,什么应该是验证\u附件\u内容\u类型配置,以便能够上载代码文件。在我的情况下,我想上传.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 我得到以下错误: R has
验证\u附件\u内容\u类型
配置,以便能够上载代码文件。在我的情况下,我想上传.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
我得到以下错误:
R has contents that are not what they are reported to be
R is invalid
R content type is invalid
我看了这个mime类型列表
但我找不到用于.R文件的。但在执行此命令时:
file --mime-type compare_datasets.R
我得到这个结果:
compare_datasets.R: text/plain
为什么
text/plain
不起作用?对于代码文件,可以使用text/plain
MIME类型
validates_attachment_content_type :r, :content_type => 'text/plain'
可以找到许多这样的文件结尾通过在mime类型初始值设定项中执行此操作,我可以使其正常工作:
Paperclip.options[:content_type_mappings] = {r: "text/plain"}
在模型中:
class RFile < ActiveRecord::Base
has_attached_file :r, url: "/system/:attachment/:id/:basename.:extension"
validates_attachment_file_name :r, matches: [/r\Z/, /R\Z/]
do_not_validate_attachment_file_type :r
end
class-RFile
我尝试使用text/plain,但仍然无法上载文件。我用代码和错误编辑了问题。请尝试使用此text/x-r
mime类型
class RFile < ActiveRecord::Base
has_attached_file :r, url: "/system/:attachment/:id/:basename.:extension"
validates_attachment_file_name :r, matches: [/r\Z/, /R\Z/]
do_not_validate_attachment_file_type :r
end