Tag: 回形针validation

回形针:无法附加XLS(但DOC工作)

我无法附加XLS文件,但DOC工作: 附件文件内容类型无效 附件文件无效 这是日志: Parameters: … “files”=>[#<ActionDispatch::Http::UploadedFile:0x0000000daf7730 @tempfile=#, @original_filename=”Chocolate_Store1.xls”, @content_type=”application/vnd.ms-excel”, @headers=”Content-Disposition: form-data; name=\”deal[files][]\”; filename=\”Chocolate_Store1.xls\”\r\nContent-Type: application/vnd.ms-excel\r\n”>], … Command :: file -b –mime “C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170511-47156-1rqzd0q.xls” (1.0ms) ROLLBACK Rendering deals/edit.html.erb within layouts/application 当我测试类型时: >file -b –mime “C:/Users/Chloe/AppData/Local/Temp/1f1fb4d71efc0bd245abd7b5b9aa661220170511-47156-1rqzd0q.xls” application/vnd.ms-office; charset=binary 我在接受列表中有这种类型: class Attachment < ApplicationRecord has_attached_file :file validates_attachment_content_type :file, content_type: [ "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.oasis.opendocument.text", "application/vnd.ms-excel", "application/vnd.ms-office", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.oasis.opendocument.spreadsheet" ] […]

Rails 4,Paperclip 4.2.1在二进制文件上传时出错

我使用rails 4和paperclip 4.2.1进行了以下设置 class Post allowed_content_type, :message=> “Only #{allowed_content_type} is allowed” 我在我的application.rb中有这个 <body data-controller="” data-action=”” data-no-turbolink=”true”> 后控制器很简单 def update Post.transaction do @post.attributes = (artifact_params) if @artifact.errors.blank? redirect_to(@artifact, :notice => ‘Evidence item updated successfully’) else render :action => ‘edit’ raise ActiveRecord::Rollback end 它与所有其他文件类型完美配合。 我尝试二进制文件时出错。 这是错误: Posts中的编码:: UndefinedConversionError #refate app / views / layouts / application.html.erb第58行引出: 56: […]

validationPaperclip中的扩展 – Ruby on Rails

我发现Paperclip可以validation文件内容类型,即image / jpeg,但我想专门validation扩展名。 这是因为我正在使用一个不起作用的扩展,它不会获得一致的内容类型。 有人知道这是可行的,还是一个很好的方法呢?

从3.5升级到Paperclip 4.1时没有validates_attachment_file_name

我们的代码看起来像磨纸夹的运行: has_merchants_attached_file :pdf, storage: :s3, s3_credentials: Mbc::DataStore.s3_credentials, s3_permissions: :private, path: “:identifier_template.pdf”, bucket: Mbc::DataStore.forms_and_templates_bucket_name validates_attachment_file_name :pdf, :matches => [/pdf\Z/] 这会产生错误: undefined method `validates_attachment_file_name’ for # 有趣的是,当我们降级到3.5时,我们遇到了同样的问题。 生成它的控制器是: def index @fidelity_templates = FidelityTemplate.order(“identifier asc”).all end 另外: def has_merchants_attached_file(attribute, options={}) if Rails.env.test? || Rails.env.development? has_attached_file attribute, path: “paperclip_attachments/#{options[:path]}” else has_attached_file attribute, options end end 有什么可能导致这种情况的想法?