简体   繁体   English

在rails4中获取相同的错误消息2次回形针

[英]fetching same error messages 2 times of paperclip in rails4

Hi I have given my attachment model: 嗨,我已经给出了附件模型:

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

in my controller action have defined this: 在我的控制器操作中定义了以下内容:

 def create
    @designation = Designation.create(designation_params)
   if @designation.errors.present?
     p @designation.errors
      render :action => :new
    else
      redirect_to designations_path, notice: I18n.t('designation_created')
    end
  end

code in designation model: 指定模型中的代码:

has_one :attachment, as: :attachable
  accepts_nested_attributes_for :attachment

in en.yml 在en.yml中

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

So whenever error it shows two times I got this in my console 所以每当错误显示两次时,我都会在控制台中得到它

,

@messages={:"attachment.attach_content_type"=>["The image format you are trying to upload is not supported. Please upload an image of format JPG, GIF or PNG"], :"attachment.attach"=>["The image format you are trying to upload is not supported. Please upload an image of format JPG, GIF or PNG"]}> @messages = {:“ attachment.attach_content_type” => [“不支持您尝试上传的图像格式。请上传JPG,GIF或PNG格式的图像”],:“ attachment.attach” => [“不支持您尝试上传的图像格式。请上传JPG,GIF或PNG格式的图像“]}>

Please guide me how to overcome with this error. 请指导我如何克服此错误。 Thanks in advance. 提前致谢。

This code means if attachable type is 'Designation' or if 'Department' string is evaluated to true (I guarantee it does). 此代码表示可连接类型是“ Designation”还是“部门”字符串评估为true (我保证是)。

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

Probably you tried to wrote something like 可能您试图写类似

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM