Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:16:32+00:00 2026-06-09T05:16:32+00:00

I am having problems building a new Rails app. When trying to run @invoice.total

  • 0

I am having problems building a new Rails app.

When trying to run @invoice.total in the view, I get this error:

undefined method `*' for nil:NilClass

However, running @invoice.total works in the console. I have tried using HAML and/or ERB with the same problem.

The code which runs for @invoice.total is in the model and is below:

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

The invoice has vat_rate and discount set to 0 and each of the items (there are 3) have inc_vat as 1.

What’s the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:16:34+00:00Added an answer on June 9, 2026 at 5:16 am

    Turns out I had @invoice_item = @invoice.invoice_items.new in the show area of the invoices controller instead of @invoice_item = InvoiceItem.new for the Invoice Item creation form.

    It had been working though :/

    Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problems with this site I am building. I need a fixed width
I'm having problems building a project under the Android NDK. Most likely its due
I'm having some problems building an hierarchistic array structure - I have almost got
I'm building a Visual Studio-like application in WPF and I'm having some problems identifying
I'm having a problem with building my iPhone app..so, i finally finished it, but
Having problems with a small awk script, Im trying to choose the newest of
I'm building a calander app for Android in appcelerator, but now I'm having some
I thought I'd have a crack at building an Android app having not done
I'm building an app but having a problem when i try and open a
At this moment we are building a new architecture that is based on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.