0

エラーメッセージの表示に問題があります。

別のクラスを持つクラスがあります。

こちらです:

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--"

そして2番目: errors.add ( :base , "...teste..." )

どちらの場合も属性を表示していますが、これは必要ありません。メッセージのみを表示したいのです。コマンド : base は単に機能しません。すべてのバリエーションを試しましたが、メッセージは変わりません。

私は何を間違っていますか?誰でも私を助けることができますか?

英語でごめんなさい:P

4

0 に答える 0