私のRailsアプリにはinvoices、多くのネストされたitems.
class Invoice < ActiveRecord::Base
attr_accessible :date, :number, :items_attributes
has_many :items
accepts_nested_attributes_for :items
def total
items.map(&:total).sum
end
end
実際にデータベースに保存されたものtotalのみが計算されることを確認するにはどうすればよいですか?items
現在、私のビューでインスタンス化されただけで、まだデータベースに保存されていないtotalインクルードも含まれています。itemsnew
ご協力いただきありがとうございます。