我在显示错误消息时遇到问题。
我有一堂课,另一堂课。
这边走:
class Issue < ActiveRecord::Base
 has_many :attachments, class_name: 'IssueAttachment', dependent: :destroy, autosave:   true
 validates_associated :attachments, :message => [:base] << "-- Teste --"
和
class IssueAttachment < ActiveRecord::Base
  belongs_to :issue, counter_cache: :attachments_count
  validate :suspitious_attachment
  private
    def suspitious_attachment
      if ends_with? '.bat', '.com', '.exe', '.src', '.cmd'
        errors.add(:base, "..teste..")
      end
    end
  def ends_with?(*args)
    args.each do |arg|
      return true if attachment.path.ends_with? arg
    end
    false
  end 
在错误消息中,我想显示以下内容: ...test ...
但是现在出现的信息是:Attachments base ...teste... Attachments -- Teste --
第一条错误消息是指行: validates_associated :attachments, :message = > [:base ] << "--Teste--"
第二个:errors.add ( :base , "...teste..." )
在这两种情况下,我都在显示属性,我不想要这个,我只想显示消息。命令 : base 根本不起作用,我尝试了所有变体并且消息没有改变。
我究竟做错了什么?谁能帮我?
对不起英语:P