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
ですか?