Ruby on rails 在rails4中获取两次回形针相同的错误消息

Ruby on rails 在rails4中获取两次回形针相同的错误消息,ruby-on-rails,validation,Ruby On Rails,Validation,嗨,我给出了我的附件模型: class Attachment < ActiveRecord::Base belongs_to :attachable, polymorphic: true has_attached_file :attach, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml",

嗨,我给出了我的附件模型:

class Attachment < ActiveRecord::Base
  belongs_to :attachable, polymorphic: true
  has_attached_file :attach,
                    :storage => :s3,
                    :s3_credentials => "#{Rails.root}/config/s3.yml",
                    :url => ":s3_domain_url",
                    :path => "/contents/:id/:basename.:extension"
  validates_attachment_content_type :attach,
                                    :content_type => ['application/msword',
                                                       'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                                                       'application/pdf'],
                                    :if => Proc.new { |f| f.attachable_type == 'Interview' }
  validates_attachment_content_type :attach,
                                    :content_type => ['image/jpeg', 'image/jpg', 'image/png'],
                                    :if => Proc.new { |f| f.attachable_type == 'Designation' || 'Department' },
                                    :message => I18n.t('content_type', :scope => 'paperclip.errors.attachment')

end
指定型号中的代码:

has_one :attachment, as: :attachable
  accepts_nested_attributes_for :attachment
以英语

en.
 paperclip:
    errors:
      attachment:
        content_type: The image format you are trying to upload is not supported. Please upload an image of format JPG, GIF or PNG
        presence: Cant' be blank
所以每当出现两次错误时,我都会在控制台中看到它

, @messages={:attachment.attach\u content\u type=>[您选择的图像格式] 不支持正在尝试上载的。请上载的图像 格式JPG、GIF或PNG],:attachment.attach=>[您选择的图像格式] 不支持正在尝试上载的。请上载的图像 格式JPG、GIF或PNG]}>


请指导我如何克服这个错误。提前感谢。

此代码意味着,如果可附加类型为“指定”,或者如果“部门”字符串的计算结果为true,我保证它会

Proc.new { |f| f.attachable_type == 'Designation' || 'Department' }
也许你试着写些类似的东西

Proc.new { |f| f.attachable_type == 'Designation' || f.attachable_type ='Department' }
Proc.new { |f| f.attachable_type == 'Designation' || f.attachable_type ='Department' }