私はしばらくこれに苦労してきました。Rails 3.2で検証するためにネストされた属性を取得しようとしていますが、うまくいきません。ネストされた属性の検証を完全に無視しているようです。以下は、機能しない検証の例です。
class Invoice < ActiveRecord::Base
validates :description, :presence => true
belongs_to :client_branch
has_many :invoice_items
accepts_nested_attributes_for :invoice_items, :allow_destroy => true
end
class InvoiceItem < ActiveRecord::Base
belongs_to :invoice
validate :thisisatest
def thisisatest
errors.add(:qty, 'QTY NOT VALIDATING TEST.')
end
end
一部の InvoiceItems を含む Invoice を保存すると、カスタム検証によって明らかに :qty 属性のエラーが追加されていても、正常に保存されます。ネストされた検証が機能するためにモデルに追加する必要があるものはありますか、それとも他に何か不足している可能性がありますか?