我们的代码看起来像普通的回形针:
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 #<Class:0x007fba67d25fe0>
有趣的是,当我们将等级降回 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
有什么想法可能导致这种情况吗?
您可以在此处阅读有关提供的验证器的信息:
https://github.com/thoughtbot/paperclip#validations https://github.com/thoughtbot/paperclip#validations
包含的验证器是:
- 附件内容类型验证器
- 附件存在验证器
- 附件大小验证器
它们可以通过以下任一方式使用:
# New style:
validates_with AttachmentPresenceValidator, :attributes => :avatar
# Old style:
validates_attachment_presence :avatar
更新 ...
如果您进一步阅读我上面给出的链接,您将看到有关安全验证的部分(感谢 Kirti Thorat):
https://github.com/thoughtbot/paperclip#security-validations https://github.com/thoughtbot/paperclip#security-validations
他们给出了如何验证文件名格式的示例:
# Validate filename
validates_attachment_file_name :avatar, :matches => [/png\Z/, /jpe?g\Z/]
从您的代码片段看来,您的验证应该按原样工作。
但是,我从未见过使用这种语法的回形针:
has_merchants_attached_file ...
也许这就是你问题的根源?您通常会使用以下命令将文件附加到模型:
has_attached_file :pdf ...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)