0

新しい Rails アプリの作成に問題があります。

@invoice.totalビューで実行しようとすると、次のエラーが発生します。

undefined method `*' for nil:NilClass

ただし、実行@invoice.totalはコンソールで機能します。同じ問題で HAML や ERB を使用してみました。

実行されるコード@invoice.totalはモデル内にあり、以下のとおりです。

def items_total
  items_total = 0
  self.invoice_items.each do |i|
    items_total += i.price * i.quantity
  end
  items_total
end


# instead of copying this code all of the time
def vat_calc
  (1 + self.vat_rate / 100)
end

def discount_calc
  (1 - self.discount / 100)
end

# total times to add vat on top and remove discount
def total
  items_total * discount_calc * vat_calc
end

請求書の vat_rate と discount は 0 に設定されており、各項目 (3 つある) の inc_vat は 1 に設定されています。

どうしたの?

4

1 に答える 1

0

請求書アイテム作成フォームでは@invoice_item = @invoice.invoice_items.newなく、請求書コントローラーの表示領域にあったことがわかりました。@invoice_item = InvoiceItem.new

それ働いていました:/

ありがとう

于 2012-08-07T22:11:32.707 に答える