如何仅在Active Storage中存储.yml文件

时间:2018-05-17 11:32:36

标签: ruby-on-rails ruby rails-activestorage ruby-on-rails-5.2

我试图仅在存储.yml文件上设置验证。 通过一些研究,我做到了这一点:

class TranslationFile < ApplicationRecord
  has_one_attached :file
  validate :only_yml_type

  private
  def only_yml_type
    if file.attached? && !file.content_type.in?(%w(application/x-yaml)) 
      file.purge
      errors.add(:file, 'Must be a yaml file')
    end
  end
end

但是现在即使文件是.yml / .yaml我也无法存储它,我做错了吗?

0 个答案:

没有答案