私の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
インクルードも含まれています。items
new
ご協力いただきありがとうございます。